Skip to content

Bot Setup

Roi Horowitz edited this page Nov 28, 2026 · 6 revisions

Bot Setup

1. Create the Discord application

  1. Go to https://discord.com/developers/applications and click New Application.

  2. On the Bot page, click Reset Token and copy it. This is DISCORD_TOKEN; keep it secret.

  3. On General Information, copy the Application ID. This is DISCORD_CLIENT_ID.

  4. Invite the bot to your server with this URL (put your application ID in):

    https://discord.com/oauth2/authorize?client_id=YOUR_APP_ID&scope=bot+applications.commands&permissions=274877975552
    

    That grants View Channel, Send Messages, Send Messages in Threads and Read Message History. The bot needs all four in every channel and thread where people roll, because it posts damage requests, reveals and spell-save results there. For a private channel or thread, also add the bot to it.

  5. In Discord, turn on User Settings → Advanced → Developer Mode, then:

    • right-click your server → Copy Server ID: this is DISCORD_GUILD_ID;
    • right-click your own name → Copy User ID: this goes in GM_DISCORD_IDS.

2. Configure

In your copy of the bot folder (see Installation):

cp .env.example .env      # Windows: Copy-Item .env.example .env

Fill in .env:

Variable What it is
DISCORD_TOKEN The bot token from step 1.
DISCORD_CLIENT_ID The application ID.
DISCORD_GUILD_ID Your server ID. Commands are registered there.
FOUNDRY_TOKEN Any long random string. Paste the same value into the module's Bot token in Foundry.
FOUNDRY_ORIGIN The exact address you open Foundry at, e.g. https://my-foundry.example.com:30000 or http://localhost:30000. Separate several with commas.
GM_DISCORD_IDS GM user IDs, comma-separated. They get the roll DMs and can use GM commands.
ALLOWED_CHANNEL_IDS Optional. Only allow rolling in these channels; threads inside them count.
PORT HTTP port for the module to reach, default 8787.
DATA_DIR Where the bot keeps store.json, default ./data.

3. Install, register commands, start

npm install
npm run register     # registers the slash commands in your server
npm start

The log should say HTTP API listening on :8787 and Logged in to Discord as ….

Run npm run register again whenever an update adds or changes commands.

Keeping it running

For Docker, The Forge, Cloudflare Tunnel, VPS, Railway or Fly.io, see Hosting.

  • Linux / Raspberry Pi: a systemd service or pm2 (pm2 start npm --name discord-roller -- start).
  • Windows: a Task Scheduler task that runs at logon and starts npm start in the bot folder, hidden. A small .vbs launcher keeps the window hidden.
  • Fly.io / Railway / similar: mount a persistent volume at DATA_DIR, or the bot forgets rolls and snapshots on each deploy.

Reaching the bot from Foundry

The GM's browser talks to the bot directly, so the Bot URL you enter in Foundry must be reachable from that browser:

  • If Foundry is served over https, the bot URL must be https too, because browsers block mixed content. The one exception is a bot on http://localhost, which browsers allow.
  • If you open Foundry at a public address and the bot runs on localhost, Chrome may ask once to allow local network access. Allow it, or syncing fails with "Can't reach the bot".

Health check

GET /api/health returns { ok, worlds: [{ worldId, worldTitle, system, snapshotAgeDays }] }. It's useful for uptime monitors and for checking that a world has synced.

Next: Foundry Setup.

Clone this wiki locally