Skip to main content

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 adapter
Direct link to Install the adapter

Install the Discord adapter from the Chat SDK:

npm install @chat-adapter/discord

Agent configuration
Direct link to Agent configuration

Add createDiscordAdapter() to the agent's channels.adapters object:

src/mastra/agents/discord-agent.ts
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.5',
channels: {
adapters: {
discord: createDiscordAdapter(),
},
},
})

Register the agent on the Mastra instance:

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { discordAgent } from './agents/discord-agent'

export const mastra = new Mastra({
agents: { discordAgent },
})

Adapter setup
Direct link to Adapter 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:

.env
DISCORD_BOT_TOKEN=your-discord-bot-token
DISCORD_PUBLIC_KEY=your-discord-application-public-key
DISCORD_APPLICATION_ID=your-discord-application-id

Webhook URL
Direct link to Webhook 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.

On this page