> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # Discord Discord Channels 让 Mastra Agent 能够接收 Discord 交互和机器人消息。Mastra 负责 Agent 接线和 webhook 路由;Chat SDK Discord 适配器文档则介绍 Discord 应用设置、机器人权限和 Gateway 行为。 ## 安装适配器 从 Chat SDK 安装 Discord 适配器: **npm**: ```bash npm install @chat-adapter/discord ``` **pnpm**: ```bash pnpm add @chat-adapter/discord ``` **Yarn**: ```bash yarn add @chat-adapter/discord ``` **Bun**: ```bash bun add @chat-adapter/discord ``` ## Agent 配置 将 `createDiscordAdapter()` 添加到 Agent 的 `channels.adapters` 对象: ```typescript import { Agent } from '@mastra/core/agent' import { createDiscordAdapter } from '@chat-adapter/discord' export const discordAgent = new Agent({ id: 'discord-agent', name: 'Discord Agent', instructions: 'Answer questions and help with tasks in Discord.', model: 'openai/gpt-5.6-sol', channels: { adapters: { discord: createDiscordAdapter(), }, }, }) ``` 在 Mastra 实例上注册该 Agent: ```typescript import { Mastra } from '@mastra/core' import { discordAgent } from './agents/discord-agent' export const mastra = new Mastra({ agents: { discordAgent }, }) ``` ## 适配器设置 按照 [Chat SDK Discord 适配器文档](https://chat-sdk.dev/adapters/official/discord)完成 Discord 专用设置,包括创建应用、配置机器人 token、交互端点、权限和 Gateway 行为。 适配器从以下环境变量中读取 Discord 凭据: ```bash DISCORD_BOT_TOKEN=your-discord-bot-token DISCORD_PUBLIC_KEY=your-discord-application-public-key DISCORD_APPLICATION_ID=your-discord-application-id ``` ## Webhook URL Mastra 根据 Agent ID 和适配器键生成 Discord webhook 路由: ```text /api/agents/discord-agent/channels/discord/webhook ``` 使用公开的 Mastra Server URL 作为基础 URL: ```text https://your-app.example.com/api/agents/discord-agent/channels/discord/webhook ``` 在 Discord 适配器文档要求填写交互端点或 webhook URL 的任何位置使用此 URL。Discord 的常规消息事件可能需要在生成的 webhook 路由之外设置 Gateway;请按照 Chat SDK 适配器文档完成该流程。 ## 相关内容 - [Channels 概览](https://mastra.zisheng.pro/docs/capabilities/channels/overview) - [更多适配器](https://mastra.zisheng.pro/docs/capabilities/channels/other-adapters)