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

# Discord 工具

## 代码

```python cookbook/tools/discord_tools.py theme={null}
from agno.agent import Agent
from agno.tools.discord import DiscordTools

discord_tools = DiscordTools(
    bot_token=discord_token,
    enable_messaging=True,
    enable_history=True,
    enable_channel_management=True,
    enable_message_management=True,
)

discord_agent = Agent(
    name="Discord Agent",
    instructions=[
        "你是一个可以执行各种操作的 Discord 机器人。",
        "你可以发送消息、读取消息历史记录、管理频道以及删除消息。",
    ],
    tools=[discord_tools],
    show_tool_calls=True,
    markdown=True,
)

channel_id = "YOUR_CHANNEL_ID"
server_id = "YOUR_SERVER_ID"

discord_agent.print_response(
    f"向频道 {channel_id} 发送消息 'Hello from Agno!'", stream=True
)

discord_agent.print_response(f"获取频道 {channel_id} 的信息", stream=True)

discord_agent.print_response(f"列出服务器 {server_id} 中的所有频道", stream=True)

discord_agent.print_response(
    f"获取频道 {channel_id} 的最后 5 条消息", stream=True
)
```

## 用法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="设置你的 Discord Token">
    ```bash theme={null}
    export DISCORD_BOT_TOKEN=xxx
    export OPENAI_API_KEY=xxx
    ```
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U discord.py openai agno
    ```
  </Step>

  <Step title="运行 Agent">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/tools/discord_tools.py
      ```

      ```bash Windows theme={null}
      python cookbook/tools/discord_tools.py
      ```
    </CodeGroup>
  </Step>
</Steps>
