Discord server bot for local development first, with future hosted deployment.
Pick one of two paths. The Docker path produces a reproducible runtime that matches CI; the local path keeps iteration tight.
- Install Bun 1.3 or later.
- Run
bun install. - Provide the required environment variables — see Environment. The exact source is left to the host (CI secret, secret manager, exported shell variables, or — only as a last resort — a local
.envfile that is not committed)..env.exampledocuments the schema and is the source of truth; do not rely on it for real secrets.
- Install Docker Engine 24+ and the Compose v2 plugin.
- Copy
.env.exampleto.envand fill inDISCORD_TOKEN,DISCORD_CLIENT_ID,DISCORD_GUILD_ID. Compose loads it viaenv_file:; the secrets never enter the image layer. docker compose up --build. Thebotservice builds theruntimestage ofContainerfile, listens on port8080for/health, and persistsdata/in a named volume (bot-data).docker compose logs -f botto follow logs.docker compose downto stop.
The Compose path targets runtime — the slim Node 22 image with the compiled dist/index.js. For source iteration with hot reload, fall back to the local path (bun run dev); the dev container target is not part of issue #27's scope.
If a bot token is ever pasted into chat, logs, a commit, or an agent result, rotate it immediately in the Discord Developer Portal and re-source the new value from your secret manager.
| Variable | Required | Notes |
|---|---|---|
DISCORD_TOKEN |
yes | Bot token from the Discord Developer Portal |
DISCORD_CLIENT_ID |
yes | Application (bot) client ID |
DISCORD_GUILD_ID |
yes | Development guild ID |
DISCORD_ENABLE_MESSAGE_CONTENT |
no | Set to true to enable the privileged Message Content intent (also enable it on the Developer Portal side) |
TIMEKEEPER_RUN_ON_READY |
no | true runs the timekeeper session immediately on ClientReady and compresses in-session minutes to 1 second for testing. Without it the timekeeper schedules for the next 21:00 JST. |
CONSENT_CHANNEL_ID |
no | Enables the consent registry. The bot reuses or creates its own consent message in this channel and adds scope reactions automatically. |
CONSENT_GUILD_ID |
no | Guild override for the consent channel. Defaults to DISCORD_GUILD_ID. |
CONSENT_MESSAGE_ID |
no | Optional existing-message override. Normally leave unset and let the bot manage its own message. |
CONSENT_EMOJI |
no | Optional emoji-to-scope mapping. Defaults to 📊 activity, 🟢 presence, 👤 profile, 💬 message history. |
CONSENT_POLICY_VERSION |
no | Current consent policy version. Defaults to v0.2.0. |
VOICE_CONNECTION_TIMEOUT_MS |
no | Maximum milliseconds to wait for a voice connection to reach the Ready state before giving up (and triggering a stage reconnect). Defaults to 30000. |
Validation lives in src/config.ts (Zod). The bot refuses to start with a clear error if a required variable is missing or empty.
bun run dev: Start the bot in watch mode.bun run start: Start the bot once.bun run lint: Run ESLint.bun run test: Run tests.bun run build: Type-check and build todist/.
bun is used as the package manager and script runner, but the bot itself runs on Node via tsx. This is intentional because Discord voice features are more reliable there.
- Enable
MESSAGE CONTENT INTENTandSERVER MEMBERS INTENTin the Discord Developer Portal. DISCORD_ENABLE_MESSAGE_CONTENT=trueis only needed afterMESSAGE CONTENT INTENTis enabled in the Discord Developer Portal.- Avoid using an invite URL with
permissions=8unless you intentionally want full administrator access. - For early development, invite the bot with only the permissions it currently needs.
- Environment variable validation
- Discord client bootstrap with intents for:
- guild events
- message reactions
- message content
- voice state tracking
Next, feature handlers can be added for reaction roles, pinned templates, and voice timers.
Reaction role rules are defined in src/features/reaction-roles/config.ts.
Each rule needs:
messageId: the target message to watchemoji: a unicode emoji like🔥, or a custom emoji IDroleId: the role to add or remove
Replace the placeholder values in that file with your real Discord IDs before testing the feature.
The daily timekeeper is configured in src/features/timekeeper/config.ts.
Current behavior:
- Starts every day at
21:00JST - Joins the configured voice channel
- Plays one audio clip at each phase start
- Plays another audio clip one minute before each phase ends
- Sends a text message only at phase start
Before using it:
- Replace
textChannelIdandvoiceChannelIdwith real Discord channel IDs - Keep the generated wav files under
tmp-audio/ - Ensure the bot can
View Channel,Send Messages,Connect, andSpeak