@mastra/core
Version:
98 lines (67 loc) • 2.52 kB
Markdown
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
# 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
Install the Discord adapter from the Chat SDK:
**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 configuration
Add `createDiscordAdapter()` to the agent's `channels.adapters` object:
```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(),
},
},
})
```
Register the agent on the Mastra instance:
```typescript
import { Mastra } from '@mastra/core'
import { discordAgent } from './agents/discord-agent'
export const mastra = new Mastra({
agents: { discordAgent },
})
```
## Adapter setup
Follow the [Chat SDK Discord adapter docs](https://chat-sdk.dev/adapters/official/discord) 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:
```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 generates the Discord webhook route from the agent ID and adapter key:
```text
/api/agents/discord-agent/channels/discord/webhook
```
Use your public Mastra server URL as the base URL:
```text
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.
## Related
- [Channels overview](https://mastra.ai/docs/capabilities/channels/overview)
- [More](https://mastra.ai/docs/capabilities/channels/other-adapters)