Discord
Discord channels let a Mastra agent receive Discord interactions and bot messages. Mastra handles the agent wiring and webhook route; the Chat SDK Discord adapter docs cover Discord application setup, bot permissions, and Gateway behavior.
Install the adapterInstall the adapter的直接链接
Install the Discord adapter from the Chat SDK:
- npm
- pnpm
- Yarn
- Bun
npm install @chat-adapter/discord
pnpm add @chat-adapter/discord
yarn add @chat-adapter/discord
bun add @chat-adapter/discord
Agent configurationAgent configuration的直接链接
Add createDiscordAdapter() to the agent's channels.adapters object:
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(),
},
},
})
Register the agent on the Mastra instance:
import { Mastra } from '@mastra/core'
import { discordAgent } from './agents/discord-agent'
export const mastra = new Mastra({
agents: { discordAgent },
})
Adapter setupAdapter setup的直接链接
Follow the Chat SDK Discord adapter docs for Discord-specific setup, including application creation, bot tokens, interaction endpoints, permissions, and Gateway behavior.
The adapter reads Discord credentials from environment variables such as:
DISCORD_BOT_TOKEN=your-discord-bot-token
DISCORD_PUBLIC_KEY=your-discord-application-public-key
DISCORD_APPLICATION_ID=your-discord-application-id
Webhook URLWebhook URL的直接链接
Mastra generates the Discord webhook route from the agent ID and adapter key:
/api/agents/discord-agent/channels/discord/webhook
Use your public Mastra server URL as the base URL:
https://your-app.example.com/api/agents/discord-agent/channels/discord/webhook
Use this URL anywhere the Discord adapter docs ask for the interactions endpoint or webhook URL. Discord regular message events may require Gateway setup outside the generated webhook route; follow the Chat SDK adapter docs for that path.