> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Discord Bot

> Create a Discord bot powered by Agno agents for community support, moderation, or custom commands.

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:

```python theme={null}
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()
```

<Note>
  The Discord bot automatically creates threads for conversations and maintains context within each thread.
</Note>

## Setup and Configuration

<Steps>
  <Step title="Prerequisites">
    Ensure you have the following:

    * Python 3.7+
    * A Discord account with server management permissions
    * Install the Discord library: `pip install discord.py`
  </Step>

  <Step title="Create a Discord Application">
    1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
    2. Click "New Application"
    3. Provide an application name (e.g., "My Agno Bot")
    4. Accept the Developer Terms of Service
    5. Click "Create"
  </Step>

  <Step title="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
  </Step>

  <Step title="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
  </Step>

  <Step title="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:

    ```bash theme={null}
    DISCORD_BOT_TOKEN="your_bot_token_here"
    ```
  </Step>

  <Step title="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
  </Step>

  <Step title="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
  </Step>
</Steps>

<Note>
  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](/deploy/templates) for production setup.
</Note>

## Developer Resources

* [Discord Integration](/integrations/discord/overview)
* [Deployment Templates](/deploy/templates)
* [Discord](https://agno.link/discord)
