Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions agent-os/interfaces/discord/introduction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
---
title: Discord
sidebarTitle: "Discord"
description: Host agents as Discord bots with slash commands and @mention support.
---

Use the Discord interface to serve Agents, Teams, or Workflows on Discord. It supports two concurrent transports: HTTP webhook for slash commands and Gateway WebSocket for @mentions and DMs.

Check warning on line 7 in agent-os/interfaces/discord/introduction.mdx

View check run for this annotation

Mintlify / Mintlify Validation (agno-v2) - vale-spellcheck

agent-os/interfaces/discord/introduction.mdx#L7

Did you really mean 'DMs'?

## Setup Steps

Follow the Discord setup guide in the [production docs](/production/interfaces/discord).

Required configuration:

- `DISCORD_BOT_TOKEN` (Bot token from the Developer Portal)
- `DISCORD_PUBLIC_KEY` (Application public key for signature verification)
- `DISCORD_APPLICATION_ID` (Application ID for webhook API calls)
- A registered `/ask` slash command
- An ngrok tunnel (for local development) with the Interactions Endpoint URL pointing to `/discord/interactions`

## Example Usage

Create an agent, expose it with the `Discord` interface, and serve via `AgentOS`:

```python basic.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.os import AgentOS
from agno.os.interfaces.discord import Discord

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

agent_os = AgentOS(
agents=[basic_agent],
interfaces=[Discord(agent=basic_agent, stream=True)],
)
app = agent_os.get_app()

if __name__ == "__main__":
agent_os.serve(app="basic:app", port=7777, reload=True)
```

## Core Components

- `Discord` (interface): Wraps an Agno `Agent`, `Team`, or `Workflow` for Discord integration via FastAPI.
- `AgentOS.serve`: Serves the FastAPI app using Uvicorn.

## `Discord` Interface

Main entry point for Agno Discord applications.

### Initialization Parameters

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `agent` | `Optional[Agent]` | `None` | Agno `Agent` instance. |
| `team` | `Optional[Team]` | `None` | Agno `Team` instance. |
| `workflow` | `Optional[Workflow]` | `None` | Agno `Workflow` instance. |
| `prefix` | `str` | `"/discord"` | Custom FastAPI route prefix. |
| `tags` | `Optional[List[str]]` | `None` | FastAPI route tags. Defaults to `["Discord"]`. |
| `stream` | `bool` | `False` | Enable streaming responses that progressively update the message. Only works for Agent and Team. |
| `show_reasoning` | `bool` | `True` | Show reasoning content (wrapped in italics) before the final answer. |
| `max_message_chars` | `int` | `1900` | Maximum characters per message. Discord's limit is 2000; 1900 leaves room for the `[1/N]` prefix on multi-part messages. |
| `allowed_guild_ids` | `Optional[List[str]]` | `None` | Restrict the bot to specific guild (server) IDs. |
| `allowed_channel_ids` | `Optional[List[str]]` | `None` | Restrict the bot to specific channel IDs. |
| `discord_bot_token` | `Optional[str]` | `None` | Bot token. Falls back to `DISCORD_BOT_TOKEN` env var. |
| `reply_in_thread` | `bool` | `True` | Create a new thread for each @mention conversation in guild channels. |

Provide exactly one of `agent`, `team`, or `workflow`.

### Key Method

| Method | Return Type | Description |
| --- | --- | --- |
| `get_router` | `APIRouter` | Returns the FastAPI router with Discord endpoints attached. |
| `get_lifespan` | `Optional[Any]` | Returns a FastAPI lifespan that manages the Gateway WebSocket and HTTP session cleanup. |

## Transports

### HTTP Webhook (Slash Commands)

Always available. Handles the `/ask` slash command via Discord's Interactions API.

**Flow:**
1. User runs `/ask message:Hello`
2. Discord sends a signed POST to `/discord/interactions`
3. Bot verifies the Ed25519 signature and responds with a deferred message
4. Background task processes the request and edits the response

**Endpoint:** `POST /discord/interactions`

- Handles PING verification and APPLICATION_COMMAND interactions
- Verifies Ed25519 signatures using `DISCORD_PUBLIC_KEY`
- Includes replay protection (rejects requests older than 5 minutes)

### Gateway WebSocket (@Mentions and DMs)

Auto-activates when `discord.py` is installed and a bot token is available. Falls back to HTTP-only otherwise.

**Flow:**
1. User @mentions the bot or sends a DM
2. Bot receives the message via WebSocket
3. Bot creates a thread (if `reply_in_thread=True`) and processes the message
4. Response is sent to the thread/channel

**Features:**
- Typing indicator shown while processing
- Auto-thread creation for guild @mentions
- Replies in-place for existing threads and DMs

## Streaming Mode

When `stream=True`, the bot progressively updates the response message as content is generated:

1. Sends an initial message with the first content chunk
2. Edits the message every ~1 second as more content arrives
3. Final edit with the complete response when generation finishes
4. Overflow content (beyond 2000 chars) is sent as follow-up messages

Streaming works for both HTTP webhook and Gateway transports. It is only supported for Agent and Team — Workflows and Remote entities fall back to non-streaming mode.

## Session ID Scheme

Session IDs use a `dc:` prefix to namespace Discord sessions:

| Format | Context |
| --- | --- |
| `dc:dm:{channel_id}` | Direct messages |
| `dc:thread:{channel_id}` | Thread channels (including auto-created threads) |
| `dc:channel:{channel_id}:user:{user_id}` | Guild channels (scoped per user) |

## Media Support

### Inbound (User to Bot)

The bot accepts attachments on the `/ask` slash command and on @mention messages. Files are classified by content type:

| Content Type | Agno Media Type |
| --- | --- |
| `image/*` | `Image` |
| `video/*` | `Video` |
| `audio/*` | `Audio` |
| Everything else | `File` |

Attachments larger than 25 MB are skipped.

### Outbound (Bot to User)

Tool-generated media (e.g., DALL-E images, ElevenLabs audio) is sent as Discord file attachments.

## Testing the Integration

1. Start the server: `python my_bot.py`
2. Start ngrok: `ngrok http 7777`
3. Set the Interactions Endpoint URL in the Developer Portal
4. Test slash commands: `/ask message:Hello`
5. Test @mentions: `@YourBot What is quantum computing?`
6. Test DMs: Send a direct message to the bot

## Troubleshooting

- **403 Invalid signature** — Verify `DISCORD_PUBLIC_KEY` is set correctly
- **Bot not responding to @mentions** — Ensure the Gateway is connected (check logs for "Discord Gateway connected as ...")
- **Slash command not appearing** — Register commands via the API (see setup guide) and wait a few minutes for propagation
- **Thread creation fails** — Bot needs `Manage Threads` permission in the channel
- **"This interaction failed"** — Check that your server is reachable via ngrok and the Interactions Endpoint URL is correct
9 changes: 8 additions & 1 deletion agent-os/interfaces/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Interfaces"
sidebarTitle: "Overview"
description: "Expose Agno agents through various communication protocols and platforms"
keywords: [interfaces, a2a, ag-ui, slack, whatsapp, protocols, integration]
keywords: [interfaces, a2a, ag-ui, slack, discord, whatsapp, telegram, protocols, integration]
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keywords include telegram, but this page doesn’t mention Telegram and the “Available Interfaces” section doesn’t link to a Telegram interface. Consider removing telegram from keywords (or adding the corresponding Telegram interface card/link) so search/SEO metadata matches the actual content.

Suggested change
keywords: [interfaces, a2a, ag-ui, slack, discord, whatsapp, telegram, protocols, integration]
keywords: [interfaces, a2a, ag-ui, slack, discord, whatsapp, protocols, integration]

Copilot uses AI. Check for mistakes.
---

Interfaces enable exposing Agno agents, teams, and workflows through various communication protocols and platforms. Each interface provides a standardized way to connect Agno agents to external systems, messaging platforms, and frontend applications.
Expand All @@ -24,6 +24,13 @@ Interfaces enable exposing Agno agents, teams, and workflows through various com
>
Deploy agents as Slack applications for team collaboration
</Card>
<Card
title="Discord"
icon="discord"
href="/agent-os/interfaces/discord/introduction"
>
Run agents as Discord bots with slash commands, @mentions, and streaming
</Card>
<Card
title="WhatsApp"
icon="whatsapp"
Expand Down
2 changes: 1 addition & 1 deletion deploy/interfaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Interfaces connect your apps to the platforms and protocols your users already u
Deploy agents as Slack apps that respond to messages and commands.
</Card>
<Card title="Discord" icon="discord" href="/deploy/interfaces/discord/overview">
Run agents as Discord bots for support, moderation, or custom commands.
Deploy agents as Discord bots with slash commands, @mentions, and streaming.
</Card>
<Card title="WhatsApp" icon="whatsapp" href="/deploy/interfaces/whatsapp/overview">
Connect agents to WhatsApp Business for customer interactions.
Expand Down
130 changes: 30 additions & 100 deletions deploy/interfaces/discord/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,115 +1,45 @@
---
title: "Discord Bot"
description: "Create a Discord bot powered by Agno agents for community support, moderation, or custom commands."
title: "Overview"
description: "Deploy Agno agents as Discord bots."
---

Agno makes it easy to deploy your agents on Discord with just 2 extra lines of code.
The Discord interface lets you serve Agno agents, teams, and workflows as Discord bots. It supports two concurrent transports: HTTP webhook (slash commands) and Gateway WebSocket (@mentions and DMs).

Check warning on line 6 in deploy/interfaces/discord/overview.mdx

View check run for this annotation

Mintlify / Mintlify Validation (agno-v2) - vale-spellcheck

deploy/interfaces/discord/overview.mdx#L6

Did you really mean 'DMs'?

This example creates a simple Agno agent for answering questions in your Discord server:
## Key Features

- **Dual transport** - Slash commands via HTTP webhook and @mentions/DMs via Gateway WebSocket
- **Streaming responses** - Progressively updates messages as content is generated (Agent and Team)
- **Thread support** - Auto-creates threads for each conversation, keeping channels clean
- **Full media support** - Handles image, video, audio, and file attachments in both directions
- **Works with Agent, Team, and Workflow** - Any Agno entity can power a Discord bot

## Quick Start

```python
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
from agno.os import AgentOS
from agno.os.interfaces.discord import Discord

<Steps>
agent = Agent(name="Bot", model=OpenAIChat(id="gpt-4o-mini"))

<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
DISCORD_BOT_TOKEN="your_bot_token_here"
agent_os = AgentOS(
agents=[agent],
interfaces=[Discord(agent=agent, stream=True)],
)
app = agent_os.get_app()
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Quick Start” snippet builds app = agent_os.get_app() but doesn’t show how to actually run/serve it. Add a minimal if __name__ == "__main__": ... (or an explicit agent_os.serve(...) / uvicorn command) so the quick start is runnable like the other interface overviews.

Suggested change
app = agent_os.get_app()
app = agent_os.get_app()
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)

Copilot uses AI. Check for mistakes.
```

</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>
## Required Configuration

<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](/production/templates/overview) for production setup.
</Note>
| Variable | Description |
| -------- | ----------- |
| `DISCORD_BOT_TOKEN` | Bot token from the [Discord Developer Portal](https://discord.com/developers/applications) |
| `DISCORD_PUBLIC_KEY` | Application public key for webhook signature verification |
| `DISCORD_APPLICATION_ID` | Application ID for webhook API calls |

## Developer Resources
## Resources

- [Discord Integration](/integrations/discord/overview)
- [Deployment Templates](/production/templates/overview)
- [Discord](https://agno.link/discord)
- [Setup Guide](/production/interfaces/discord) - Step-by-step bot creation, permissions, and webhook setup
- [Technical Reference](/agent-os/interfaces/discord/introduction) - Parameters, endpoints, transports, and session handling
- [Cookbook Examples](https://github.com/agno-agi/agno/tree/main/cookbook/05_agent_os/interfaces/discord) - Ready-to-run examples
3 changes: 2 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2873,7 +2873,8 @@
"agent-os/interfaces/whatsapp/introduction",
"agent-os/interfaces/a2a/introduction",
"agent-os/interfaces/ag-ui/introduction",
"agent-os/interfaces/slack/introduction"
"agent-os/interfaces/slack/introduction",
"agent-os/interfaces/discord/introduction"
]
},
{
Expand Down
Loading
Loading