Skip to main content
Agno makes it easy to deploy your agents on Discord with just 2 extra lines of code. This example creates a simple Agno agent for answering questions in your Discord server:
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.integrations.discord import DiscordClient

basic_agent = Agent(
    name="Basic Agent",
    model=OpenAIChat(id="gpt-5.2"), 
    add_history_to_context=True,
    num_history_runs=3,
    add_datetime_to_context=True,
)

discord_agent = DiscordClient(basic_agent)
if __name__ == "__main__":
    discord_agent.serve()
The Discord bot automatically creates threads for conversations and maintains context within each thread.

Setup and Configuration

1

Prerequisites

Ensure you have the following:
  • Python 3.7+
  • A Discord account with server management permissions
  • Install the Discord library: pip install discord.py
2

Create a Discord Application

  1. Go to Discord Developer Portal
  2. Click “New Application”
  3. Provide an application name (e.g., “My Agno Bot”)
  4. Accept the Developer Terms of Service
  5. Click “Create”
3

Create a Bot User

  1. In your application settings, navigate to the “Bot” section
  2. Click “Add Bot”
  3. Confirm by clicking “Yes, do it!”
  4. In the “Token” section, click “Copy” to copy your bot token
  5. Save this token securely
4

Configure Bot Permissions and Intents

  1. In the Bot settings, scroll down to “Privileged Gateway Intents”
  2. Enable the following intents:
    • Server Members Intent (for member-related events)
    • Message Content Intent (required for reading message content)
  3. Set “Bot Permissions” to ensure your bot has permission to:
    • Send Messages
    • Read Message History
    • Create Public Threads
    • Attach Files
    • Embed Links
5

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:
DISCORD_BOT_TOKEN="your_bot_token_here"
6

Invite Bot to Your Discord Server

  1. In your application settings, go to “OAuth2” > “URL Generator”
  2. Under “Scopes”, select:
    • bot
  3. Under “Bot Permissions”, select the permissions your bot needs:
    • Send Messages
    • Create Public Threads
    • Read Message History
    • Attach Files
    • Embed Links
  4. Copy the generated URL, navigate to it in your browser, and select the server where you want to add the bot
7

Test Your Bot

  1. Run your bot: python discord_bot.py
  2. Go to your Discord server
  3. Send a message in any channel where your bot has access
  4. Your bot should automatically create a thread and respond
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.

Developer Resources