Repository navigation
Hosting
The bot is a small Node.js app (or Docker container) that has to:
- stay on. Players roll while you're away, and Discord needs a constant connection.
-
keep its data. Everything lives in
DATA_DIR/store.json, so give it a persistent disk. -
be reachable from the GM's browser. The module talks to it directly, and if Foundry is served over https (The Forge, most hosts, any public setup), the bot needs an https address too. Browsers only allow plain
http://for a bot onhttp://localhost, on the GM's own machine.
| Your Foundry | Recommended bot hosting |
|---|---|
| The Forge or another managed host | Home PC / Pi + Cloudflare Tunnel (free), or a VPS / Railway / Fly.io |
| Self-hosted on a VPS | The same VPS, behind your reverse proxy |
| Self-hosted at home | The same machine, with a Cloudflare Tunnel or your existing reverse proxy |
Local only (http://localhost:30000, everyone on your PC) |
The same PC, http://localhost:8787; no https needed |
Avoid hosts that sleep when idle, such as free "web service" tiers that spin down after a few minutes. The bot would drop off Discord and commands would fail.
Whatever you choose, these two settings must match:
-
FOUNDRY_ORIGIN(bot.env): exactly the address in the GM's address bar when the world is open, e.g.https://yourgame.forge-vtt.com. List every address people use, comma-separated (e.g. a custom domain too). -
Bot URL (Foundry setup window): the bot's public address, e.g.
https://roller.example.com.
Registering commands only needs the three Discord variables, so you can run npm run register once from any PC with a copy of the bot and a .env. You don't have to run it on the server.
- Install the module from the manifest URL (Installation) and enable it in your world.
- Host the bot with any option below. The Forge only runs Foundry, not your own programs, so the bot can't live there.
- Set
FOUNDRY_ORIGINto your game's address as it appears in the browser while the world is open, e.g.https://yourgame.forge-vtt.com. - In Set up Discord, enter the bot's https address as the Bot URL.
The Data-folder warning in Security doesn't apply here, because the bot never runs on the Forge.
Free, no port forwarding, real https. It needs a domain on Cloudflare (a cheap one works), and the machine must stay on.
- Run the bot on the machine (Bot Setup) and confirm
http://localhost:8787/api/healthworks there. - In the Cloudflare dashboard: Zero Trust → Networks → Tunnels → Create a tunnel (Cloudflared). Follow the install command it shows for your OS. That installs
cloudflaredas a service. - Add a public hostname, e.g.
roller.example.com, with service HTTP →localhost:8787. - Open
https://roller.example.com/api/health. It should return{"ok":true,…}. - Use
https://roller.example.comas the Bot URL.
Prefer the CLI? Use cloudflared tunnel login, then cloudflared tunnel create squire and cloudflared tunnel route dns squire roller.example.com, with an ingress rule to http://localhost:8787.
Quick tunnels (
*.trycloudflare.com) get a new address every restart, so you'd have to update the Bot URL each time. Use a named tunnel.
Any small Linux VPS works. Point a DNS A record (e.g. roller.example.com) at the server, then copy the bot/ folder there with your .env, and add:
docker-compose.yml
services:
bot:
build: .
env_file: .env
volumes:
- bot-data:/data
restart: unless-stopped
caddy:
image: caddy:2
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy-data:/data
restart: unless-stopped
volumes:
bot-data:
caddy-data:Caddyfile
roller.example.com {
reverse_proxy bot:8787
}
docker compose run --rm bot node src/register.js # once
docker compose up -dCaddy gets and renews the https certificate automatically. The Bot URL is https://roller.example.com.
Without Docker: install Node 20+ and run the bot with pm2 or a systemd service, and put Caddy or nginx in front of localhost:8787 the same way.
- Push the repository (or your fork) to GitHub and create a Railway project from it.
- In the service settings, set the root directory to
bot. Railway builds the includedDockerfile. - Add the variables from
.env.example(DISCORD_TOKEN,FOUNDRY_TOKEN,FOUNDRY_ORIGIN, …). -
Add a volume mounted at
/data. - Under networking, generate a public domain for port
8787. That https address is your Bot URL.
From the bot/ folder:
fly launch --no-deploy # uses the Dockerfile; pick a name and region
fly volumes create data --size 1
fly secrets set DISCORD_TOKEN=… DISCORD_CLIENT_ID=… DISCORD_GUILD_ID=… FOUNDRY_TOKEN=… FOUNDRY_ORIGIN=https://yourgame.forge-vtt.com GM_DISCORD_IDS=…In fly.toml, mount the volume and keep one machine running, because Fly stops idle machines by default, which would drop the bot from Discord:
[mounts]
source = "data"
destination = "/data"
[http_service]
internal_port = 8787
force_https = true
auto_stop_machines = "off"
auto_start_machines = true
min_machines_running = 1Then fly deploy. The Bot URL is https://<app-name>.fly.dev.
Run the bot on the Foundry server, outside Foundry's Data folder (Security), and give it its own subdomain on your existing reverse proxy:
Caddy
bot.example.com {
reverse_proxy localhost:8787
}
nginx
server {
server_name bot.example.com;
listen 443 ssl;
# ssl_certificate … (e.g. from certbot)
location / {
proxy_pass http://127.0.0.1:8787;
proxy_set_header Host $host;
}
}The Bot URL is https://bot.example.com, and FOUNDRY_ORIGIN is your Foundry address.
- Open
<Bot URL>/api/healthin the GM's browser. It should show{"ok":true,…}. - In Foundry, Set up Discord → Save (or Sync now).
- Check
/api/healthagain: your world should be listed withsnapshotAgeDays: 0.
If the sync fails, see Troubleshooting.
Getting started
- Installation
- Bot Setup
- Hosting (Forge, cloud, VPS)
- Foundry Setup
Using it
Systems
Reference