Install Discord dependencies:
pip install 'agno[discord]'The bot automatically creates threads for each @mention conversation and uses per-thread session tracking to maintain context. In DMs, each channel gets its own session.
Setup and Configuration
Create a Discord Application
- Go to the Discord Developer Portal
- Click “New Application”
- Provide an application name (e.g., “My Agno Bot”)
- Accept the Developer Terms of Service and click “Create”
- Note the Application ID and Public Key from the “General Information” page
Create a Bot User
- In your application settings, navigate to the “Bot” section
- Click “Reset Token” to generate a new bot token
- Copy and save this token securely — you won’t be able to see it again
Configure Bot Permissions
In the Bot settings, ensure your bot has these permissions:
- Send Messages
- Read Message History
- Create Public Threads
- Send Messages in Threads
- Manage Threads
- Attach Files
- Embed Links
Invite Bot to Your Server
- In your application settings, go to “OAuth2” > “URL Generator”
- Under “Scopes”, select
botandapplications.commands - Under “Bot Permissions”, select the permissions listed above
- Copy the generated URL, open it in your browser, and select your server
Setup Webhook with ngrok (Development)
- Run ngrok to expose your local server:
- Copy the
https://URL provided by ngrok - Set the interactions endpoint in the Discord Developer Portal:
- Go to “General Information”
- Set “Interactions Endpoint URL” to
https://<your-ngrok-url>/discord/interactions - Discord will send a verification PING — your server must be running
ngrok is used only for local development and testing. For production deployments, see the deployment tutorials.
How It Works
The Discord interface uses two concurrent transports:-
HTTP Webhook - Handles
/askslash commands via Discord’s Interactions API. The bot responds with a deferred message, processes the request in the background, and edits the response. -
Gateway WebSocket - Listens for @mentions and DMs via a persistent WebSocket connection. Auto-activates when
discord.pyis installed andDISCORD_BOT_TOKENis set.