> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Discord Discord 頻道讓 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 instance 上註冊 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 及適配器 key 產生 Discord webhook 路由: ```text /api/agents/discord-agent/channels/discord/webhook ``` 使用公開的 Mastra 伺服器 URL 作為基礎 URL: ```text https://your-app.example.com/api/agents/discord-agent/channels/discord/webhook ``` 當 Discord 適配器文件要求提供互動端點或 webhook URL 時,請使用此 URL。Discord 的一般訊息事件可能需要在所產生的 webhook 路由以外設定 Gateway;請按照 Chat SDK 適配器文件完成相關設定。 ## 相關內容 - [頻道概覽](https://mastra.zisheng.pro/zh-HK/docs/capabilities/channels/overview) - [更多](https://mastra.zisheng.pro/zh-HK/docs/capabilities/channels/other-adapters)