The Discord bot automatically creates threads for conversations and maintains context within each thread.
Setup and Configuration
Prerequisites
Ensure you have the following:
- Python 3.7+
- A Discord account with server management permissions
- Install the Discord library:
pip install discord.py
Create a Discord Application
- Go to Discord Developer Portal
- Click “New Application”
- Provide an application name (e.g., “My Agno Bot”)
- Accept the Developer Terms of Service
- Click “Create”
Create a Bot User
- In your application settings, navigate to the “Bot” section
- Click “Add Bot”
- Confirm by clicking “Yes, do it!”
- In the “Token” section, click “Copy” to copy your bot token
- Save this token securely
Configure Bot Permissions and Intents
- In the Bot settings, scroll down to “Privileged Gateway Intents”
- Enable the following intents:
- Server Members Intent (for member-related events)
- Message Content Intent (required for reading message content)
- Set “Bot Permissions” to ensure your bot has permission to:
- Send Messages
- Read Message History
- Create Public Threads
- Attach Files
- Embed Links
Setup Environment Variables
Find your bot token in the Discord Developer Portal under “Bot” > “Token”.Create a
.env file in your project root with the following content, replacing the placeholder with your actual bot token:Invite Bot to Your Discord Server
- In your application settings, go to “OAuth2” > “URL Generator”
- Under “Scopes”, select:
bot
- Under “Bot Permissions”, select the permissions your bot needs:
- Send Messages
- Create Public Threads
- Read Message History
- Attach Files
- Embed Links
- Copy the generated URL, navigate to it in your browser, and select the server where you want to add the bot
Unlike Slack and WhatsApp bots, Discord bots don’t require webhooks or ngrok. They connect directly to Discord’s Gateway API. You can deploy them on any service that supports continuous Python runtime (Railway, Render, AWS EC2, etc.). See deployment tutorials for production setup.