Build a Discord AI Agent with nanoinfra
This guide connects nanoinfra to Discord so a Discord user or server channel can talk to your self-hosted AI agent through the nanoinfra gateway.
What this guide builds
- a Discord bot application
- Message Content intent enabled
- the
discordchannel enabled in nanoinfra - one direct message or mention test
Prerequisites
- A working local nanoinfra reply:
nanoinfra agent -m "Hello!"
- Access to the Discord Developer Portal.
- A Discord server where you can invite a bot.
Install nanoinfra
Quick Start ranks four install methods easiest first. This is the first of them. Use pip, Docker or a source checkout instead if you prefer, and come back here.
uv tool install nanoinfra
nanoinfra onboard --wizard
Enable the Discord channel
Install the optional channel dependency:
nanoinfra plugins enable discord
Create a Discord application, add a bot, copy the token, and enable
MESSAGE CONTENT INTENT in the bot settings.
Merge this snippet into ~/.nanoinfra/config.json:
{
"channels": {
"discord": {
"enabled": true,
"token": "YOUR_BOT_TOKEN",
"allowChannels": [],
"groupPolicy": "mention",
"streaming": true
}
}
}
Omitting allowFrom enables pairing-only mode. A new user should DM the bot
first, get a pairing code, and be approved before using the bot in servers.
Invite the bot with permissions to read history and send messages.
Run nanoinfra gateway
nanoinfra channels status
nanoinfra gateway
Test a message
Send the bot a DM first. It should return a pairing code. Approve that code from a trusted local surface, and not the example below:
nanoinfra agent -m "/pairing approve <the code the bot sent you>"
If you missed the code, list the pending requests:
nanoinfra agent -m "/pairing"
After approval, mention it in an allowed server channel:
@your-bot Hello from Discord
Security notes
- Keep
groupPolicyasmentionfor first deployment. - Use
allowChannelsfor server channels where the bot should operate. - Prefer pairing-only mode for user access. Add
allowFromonly when you want a static allowlist. - Avoid open group behavior in busy channels until session routing is clear.
- Review tool access before inviting the bot into shared servers.
Troubleshooting
- If no messages arrive, confirm Message Content intent is enabled.
- If a DM returns a pairing code, approve it before testing normal replies.
- If server messages are ignored, check pairing approval,
allowChannels, and whether the bot was mentioned. - If the bot cannot reply, confirm the invite permissions and channel overrides.