Skip to main content

Installation

Environment Variables

Create a Discord app at the Discord Developer Portal.

Configuration Options

Setup

Webhook Handler (HTTP Interactions)

Discord HTTP Interactions are recommended for serverless environments. Set your Interactions Endpoint URL in the Discord Developer Portal.

Gateway Mode (WebSocket)

For receiving all messages (not just interactions):
Gateway mode requires a persistent connection. Not recommended for serverless platforms unless using a worker process.

Gateway Event Forwarding

Forward Gateway events to your webhook endpoint:

Features

Supported Events

HTTP Interactions:
  • PING - Discord verification (auto-handled)
  • APPLICATION_COMMAND - Slash commands
  • MESSAGE_COMPONENT - Button clicks
Gateway Events (when using startGatewayListener):
  • MESSAGE_CREATE - All messages in channels/DMs
  • MESSAGE_REACTION_ADD - Reaction added
  • MESSAGE_REACTION_REMOVE - Reaction removed

Slash Commands

Register slash commands via Discord Developer Portal, then handle them:

Buttons & Components

Create messages with buttons:
Handle button clicks:

Embeds

Cards are converted to Discord embeds:

Reactions

Add/remove emoji reactions:

File Uploads

Send files with messages:
Discord supports up to 10 files per message, max 25 MB total (50 MB with Nitro).

Threads

Discord threads are automatically detected:

Thread IDs

Discord thread IDs encode guild, channel, and thread:
Examples:
  • DM: discord:@me:987654321
  • Channel: discord:123456789:987654321
  • Thread: discord:123456789:987654321:111222333

Opening DMs

Create a DM channel with a user:

Message History

Fetch message history from a channel or thread:

Platform Limits

  • Message length: 2,000 characters
  • Embed description: 4,096 characters
  • Embeds per message: 10 embeds
  • Files per message: 10 files (25 MB total, 50 MB with Nitro)
  • Rate limits: Varies by endpoint, typically 5 requests/5 seconds per route
See Discord rate limits for details.

Code Examples

Troubleshooting

  • Verify DISCORD_PUBLIC_KEY matches the Public Key in Developer Portal
  • Ensure public key is lowercase hex (64 characters)
  • Check that signature headers are present: x-signature-ed25519, x-signature-timestamp
  • HTTP Interactions only work for slash commands and buttons
  • Use Gateway mode (startGatewayListener) to receive all messages
  • Ensure bot has MESSAGE CONTENT intent enabled in Developer Portal
  • Register commands via Discord Developer Portal or REST API
  • Commands can take up to 1 hour to sync globally
  • Use guild-specific commands for instant updates during development
  • Gateway connections require persistent runtime (not serverless)
  • Use AbortSignal to gracefully stop when deploying new version
  • Forward Gateway events to webhook for serverless processing

Required Intents & Scopes

Bot Permissions:
  • VIEW_CHANNEL - See channels
  • SEND_MESSAGES - Send messages
  • EMBED_LINKS - Send embeds
  • ATTACH_FILES - Upload files
  • ADD_REACTIONS - Add reactions
  • READ_MESSAGE_HISTORY - Fetch message history
  • USE_SLASH_COMMANDS - Respond to slash commands
Gateway Intents (for Gateway mode):
  • GUILDS - Basic guild info
  • GUILD_MESSAGES - Receive messages
  • MESSAGE_CONTENT - Read message content (privileged)
  • DIRECT_MESSAGES - Receive DMs
  • GUILD_MESSAGE_REACTIONS - Receive reactions
  • DIRECT_MESSAGE_REACTIONS - Receive DM reactions
MESSAGE_CONTENT is a privileged intent. Request it in the Developer Portal (required for verified bots).

Next Steps

Message Handling

Process messages and build conversation flows

Embeds & Components

Create rich embeds with buttons

Discord Developer Docs

Learn about Discordโ€™s Bot API

State Management

Persist data across requests