Connecting AI Agents to Discord, Lessons from Real Setup Failures
After Telegram, I tried attaching Hermes Agent to Discord too. Telegram is done with one token from BotFather, but Discord involves bot invitation and permission settings, so that part took longer. Here is what I actually went through. (measured on the operator's environment)
1. Creating the bot: Developer Portal
Telegram has BotFather as a single bot account. Discord manages things at the project level instead.
- Go to Discord Developer Portal
- Click
New Applicationin the top right, enter a name - Select
Botin the left menu, clickReset Tokento get the token - On the same screen, turn
MESSAGE CONTENT INTENTON
The token format looks like this:
MTIzNDU2Nzg5MDEyMzQ1Njc4.GaBcDe.thisIsAFakeTokenExample
Pitfall 1: Without MESSAGE CONTENT INTENT, the bot cannot read messages
If this switch is off, the bot cannot access channel message content. Even if you set every permission correctly, you get no responses. It is easy to move on after just getting the token. Check the Bot screen in the portal to make sure it is on.
2. Inviting the bot to your server
- Left menu
OAuth2โURL Generator - Check scopes
botandapplications.commands - Check bot permissions:
View Channels,Send Messages,Read Message History,Attach Files - Open the generated URL in a browser, select the server, and invite
Pitfall 2: Permission problems show up as silence
Discord does not throw errors when permissions are missing โ it just ignores messages. If the bot is online but silent, permission issues are the most likely cause. Check the server settings โ Integrations โ bot name โ permissions tab.
3. Getting your Discord user ID
Turn on Developer Mode in user settings, right-click any user, and select Copy User ID.
123456789012345678
Pitfall 3: Use the numeric ID, not the username
Filtering with @myid does not work. You need the numeric ID.
4. .env configuration
DISCORD_BOT_TOKEN=MTIzNDU2Nzg5MDEyMzQ1Njc4.GaBcDe.thisIsAFakeTokenExample
DISCORD_ALLOWED_USERS=123456789012345678
DISCORD_MESSAGE_PREFIX=!
Pitfall 4: Without a prefix, every channel message becomes a request
Discord sends all channel messages to the bot. Without a prefix, casual chat goes straight to the LLM and costs add up. I set this up without understanding the prefix concept and briefly fed an entire channel's conversation into the model.
Pitfall 5: Do not put quotes around the token
DISCORD_BOT_TOKEN="MTIzNDU2..."
Quotes get included in the token and you get 401: Unauthorized. Same trap as Telegram.
5. Running
hermes gateway start
Pitfall 6: Do not run the gateway in two places at once
Telegram gave an explicit 409 Conflict, but Discord silently retries the websocket connection. If the connection seems fine but no messages arrive, check whether another process is using the same token.
6. Comparison with Telegram
| Telegram | Discord | |
|---|---|---|
| Bot creation | Instant via BotFather | Developer Portal project |
| Required switch | None | MESSAGE CONTENT INTENT ON |
| Permissions | Allowed Users is enough | Channel permissions + Allowed Users |
| Duplicate run | 409 Conflict | Silent reconnect loop |
| Cost control | Session message count | Message prefix is mandatory |
Summary
- Developer Portal โ create Application โ Bot โ get token, turn MESSAGE CONTENT INTENT ON
- OAuth2 URL Generator with
bot+applications.commands, check 4 channel permissions - Developer Mode to get numeric user ID โ
DISCORD_ALLOWED_USERS - Write token without quotes in
.env, setDISCORD_MESSAGE_PREFIX hermes gateway startโ if it fails, check permissions โ prefix โ duplicate run in that order
Discord is channel-based, so it is better for teams. Setting up permissions is heavier than Telegram, but for a team channel it is worth it.
AI Knowledge Hub