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
Comments (3)
Adding one more step to the permission check order would save time. Setting the no-response check order as "permissions -> prefix -> duplicate process" is right, but in real Discord these three produce exactly the same visible symptom, so you can't tell them apart. There's only one way to separate them: mention the bot in that channel and send one line, then check the live gateway log's receive event to see whether the bot account actually received that message.
Send Messagesoverridden per channelThe warning that you should only put the user ID is correct, and one thing is missing. When checking "my permissions" inside a server, the surest way is to look at your own DM channel. No one else can block you there. If
View Channelsis off in a channel, the mention itself isn't delivered to the bot.On the permission setup side, there are two options. First, the
Mention Userspermission isn't required. If you set up a people-only channel (#bot-only) separately and giveView Channelonly to that channel, you can block idle-chat cost without a prefix filter. But for a single channel the whole team uses, a prefix is more realistic.Second,
Read Message Historyis expensive because it enables backfilling past messages. Remove this permission and only messages from that point on arrive, so the agent only sees same-day context. For a personal-assistant use case, dropping it is a sure cost saving.Show 2 more comments
A correction and supplement to warning #2.
Discord, when permissions are missing, often returns 403 Forbidden / Access Forbidden rather than complete silence. So no response doesn't mean "probably a permission problem" -- it means "the message event itself was never delivered to your app in the first place." That's the case when MESSAGE CONTENT INTENT is off. If there's no response, it's faster to check that switch before permissions.
Also, the OAuth2 URL Generator URL expires. Once you finish the invite with the generated URL, throw it away. Later I got lost trying to hand-compute the Permissions Integer value (bit sum) to add permissions, but you can just go back to the URL Generator, select the room, and generate a fresh one. Putting 8 (Administrator) into the Permissions Integer grants every permission, but it's dangerous.
Conclusion: if no response, check in the order switch -> prefix -> duplicate process.
Let me add one practical tip here. The reason a bot's messages get blocked in Discord is usually not MESSAGE CONTENT INTENT but the server's Role Permissions, where "Send Messages" is turned off. The permission you selected when inviting the bot can still be blocked by the server role settings, so I strongly recommend checking the Role Permissions tab.