WebSocket and fetch APIs — no additional packages required. The bot supports both direct messages and server channels, with an optional setting to require an @mention before responding in servers.
Requirements
Environment variables
| Variable | Required | Default | Description |
|---|---|---|---|
DISCORD_BOT_TOKEN | Yes | — | Bot token from the Discord developer portal |
DISCORD_ALLOWED_USER_IDS | Yes | — | Comma-separated Discord user IDs allowed to message the bot |
DISCORD_REQUIRE_MENTION | No | true | In servers, require an @mention before responding |
Setup
Create a Discord application and bot
- Go to the Discord Developer Portal.
- Click New Application and give it a name.
- Navigate to Bot in the left sidebar.
- Click Add Bot, then confirm.
- Under Privileged Gateway Intents, enable Message Content Intent — the bot needs this to read message content.
- Copy the bot token from the Token section. Keep it private.
Invite the bot to your server
- Navigate to OAuth2 → URL Generator in the developer portal.
- Under Scopes, select
bot. - Under Bot Permissions, select:
- Read Messages/View Channels
- Send Messages
- Read Message History
- Add Reactions
- Copy the generated URL and open it in your browser.
- Select your server and authorize the bot.
Get your Discord user ID
To find your user ID:
- In Discord, go to User Settings → Advanced and enable Developer Mode.
- Right-click your username anywhere in Discord and select Copy User ID.
123456789012345678.Set the environment variables
Add the values to your To allow multiple users, separate IDs with commas:
.env file:Configure mention behavior
Set This setting has no effect in direct messages — the bot always responds to DMs.
DISCORD_REQUIRE_MENTION based on how you plan to use the bot:How DISCORD_REQUIRE_MENTION works
WhenDISCORD_REQUIRE_MENTION=true (the default), the bot only responds to server channel messages in two cases:
- The bot is @mentioned in the message.
- The message is a reply to a previous bot message.
Allowlist behavior
TheisAllowedDiscordUser function controls who can message the bot.
- Empty
DISCORD_ALLOWED_USER_IDS— the bot denies all messages. Discord does not default to open like WhatsApp and Telegram. - Populated list — only user IDs in the list are accepted. All others are ignored.
Attachments
The Discord integration has full attachment support in both directions: Incoming — when you send a message with file attachments, the gateway downloads each file toATTACHMENTS_DIR (default .gateway/attachments/) and includes the file paths in the message forwarded to the agent. The agent can read the files as part of its response.
Outgoing — if the agent’s reply includes file paths, the gateway uploads them as Discord attachments alongside the reply text. Up to 10 files can be attached per message.
The gateway also tracks typing indicators: it sends a typing event to the channel while the agent is processing, and refreshes it every 8 seconds to keep the “is typing” indicator visible for long responses.
Progress indicators
While the agent processes a message, the gateway uses Discord reactions on the original message to show progress:| State | Indicator |
|---|---|
| Thinking | Typing indicator in channel |
| Waiting for permission | Reaction on original message |
| Error | Reaction on original message |
Rate limiting
TheDiscordRestClient handles Discord’s rate limits automatically. It tracks per-bucket and global rate limit headers from every API response and waits before retrying when a 429 Too Many Requests response is received. Requests are serialized per major resource key (channel, guild, or webhook) to avoid hitting bucket limits.