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

> ## Agent Instructions
> For AgentScope Python, use https://docs.agentscope.io/stable/en/index for new projects. For existing projects, check the installed agentscope version and use matching versioned documentation.
> The /latest/ alias points to the newest documentation and may move ahead of /stable/ when a development version exists. Do not mix AgentScope 1.x and 2.x APIs.
> State the AgentScope version when providing installation commands or code examples. ReMe uses its own continuously updated /reme/latest/ documentation.

# Discord

> Chat with your service's agents inside Discord.

The Discord channel connects over the Gateway WebSocket, with the bot sending and receiving messages on a long connection. The Discord channel currently supports:

* **Interactive button approval**: when an agent calls a tool that needs approval, it asks for confirmation as buttons; click to allow or deny;
* **Multimodal input**: receive image and file attachments from users and pass them to the agent;
* **Markdown**: replies render as Markdown, capped at 2000 characters per message, with longer content split automatically.

Connecting takes three steps: create an application and bot on the [Discord Developer Portal](https://discord.com/developers/applications) and get the token, start an agent service to host the channel, then add the Discord channel in the management UI.

## Prerequisites

The Discord channel depends on `discord.py`, installed with the `channel` extra:

```bash Install the dependency theme={null}
pip install "agentscope[channel]"
```

## Create Bot

Create and configure the bot on the [Discord Developer Portal](https://discord.com/developers/applications).

**1. Create an application**

Click "New Application" to create an app, and record the **Application ID** on the "General Information" page.

**2. Add a bot and get the token**

Go to the "Bot" page, add a bot, and click "Reset Token" to generate and copy the **Bot Token**. The token is a secret and is shown only once; keep it safe.

**3. Enable Message Content Intent**

On the "Bot" page, under "Privileged Gateway Intents", enable **MESSAGE CONTENT INTENT**. This is required to read message text; without it, you won't receive message content.

**4. Invite the bot to a server**

Under "OAuth2 → URL Generator", select the `bot` scope, then the permissions you need (at least "Send Messages" and "Read Message History"), and use the generated link to invite the bot to your server.

## Start Agent Service

A channel runs on top of an [agent service](https://docs.agentscope.io/en/versions/2.0.12dev/deploy/agent-service.md). Start the service with `create_app` and declare the accepted channel types via `channels`. Channels depend on a message bus (`message_bus`); use `InMemoryMessageBus` for single-machine development, and switch to `RedisMessageBus` for multi-process or multi-node deployment.

```python Start an agent service that hosts the channel theme={null}
from agentscope.app import create_app
from agentscope.app.channel import DiscordChannel
from agentscope.app.message_bus import InMemoryMessageBus
from agentscope.app.storage import RedisStorage
from agentscope.app.workspace_manager import LocalWorkspaceManager

app = create_app(
    storage=RedisStorage(host="localhost", port=6379),
    # In-memory bus for single-machine dev; switch to RedisMessageBus for multi-node
    message_bus=InMemoryMessageBus(),
    workspace_manager=LocalWorkspaceManager(basedir="./workspaces"),
    channels=[DiscordChannel],   # channel types this service accepts
)
# After starting with uvicorn, the channel feature is ready
# uvicorn.run(app, host="0.0.0.0", port=8000)
```

## Add Channel

In the management UI (see the sample frontend [`examples/web_ui`](https://github.com/agentscope-ai/agentscope/tree/main/examples/web_ui)), add a channel through a visual form, with no config to write by hand.

**1. Create a channel and pick Discord**

On the channel management page, create a channel and choose "Discord" as the platform type.

**2. Fill in the credentials**

Enter the **Application ID** and **Bot Token** from the previous step into the credential form.

**3. Configure routing rules**

Choose which agent handles messages and how sessions are scoped. See [Message Routing](https://docs.agentscope.io/en/versions/2.0.12dev/deploy/channel/routing.md) for what the rules mean.

**4. Save and enable**

Save and enable the channel; the service connects to Discord immediately and the bot comes online. @mention it in a server channel, or DM it, to begin.

> [!NOTE]
>
> The management UI maps onto the `/channels` endpoints; call them directly when you need to create channels programmatically. See the [API](https://docs.agentscope.io/en/versions/2.0.12dev/deploy/openapi.json) part of this chapter for the fields.

## Platform Config

The Discord channel has a few platform-specific switches:

| Field | Description | Default |
| - | - | - |
| `only_at_reply` | In server channels, reply only when the bot is @mentioned. DMs are unaffected and always answered | `true` |
| `show_thinking` | Include the model's reasoning in the reply | `false` |
| `show_tool_process` | Include tool calls and results in the reply | `false` |

> [!NOTE]
>
> When routing on `chat_type`, a server channel's value is `guild` and a DM's is `dm`.

## Verify and Troubleshoot

* Check the channel status in the management UI, or call `GET /channels/{id}/status` to confirm the connection is established.
* If the bot doesn't respond in a server channel, first confirm **MESSAGE CONTENT INTENT** is enabled, then check `only_at_reply` and the @-mention behavior.
* If the bot never comes online, check the Bot Token and that it has been invited to the server.

## Further Reading

> **[Message Routing](https://docs.agentscope.io/en/versions/2.0.12dev/deploy/channel/routing.md)**
>
> Route different server channels to different agents.

> **[Custom Channel](https://docs.agentscope.io/en/versions/2.0.12dev/deploy/channel/custom.md)**
>
> Connect a platform beyond the built-ins.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.