Documentation Index
Fetch the complete documentation index at: https://mintlify.com/discord/discord-interactions-js/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This guide walks you through building a complete Discord webhook server using Express.js and the discord-interactions library. You’ll learn how to handle both interactions and webhook events with proper signature verification.Quick Start
Basic Server Setup
Here’s a minimal Express server with Discord interactions:Complete Server Example
Here’s a full-featured server handling both interactions and webhook events:Middleware Configuration
❌ Wrong Approach
✅ Correct Approach
Environment Variables
Create a.env file and load it with a package like dotenv:
Error Handling
Add proper error handling to your Express server:Logging
Add request logging for debugging:Testing Locally
Using ngrok
Expose your local server to Discord:Health Check Endpoint
Use a health check for monitoring:Production Deployment
Using PM2
Keep your server running with PM2:Environment-Specific Configuration
TypeScript Setup
For TypeScript projects, add proper typing:Advanced Patterns
Command Registry
Organize commands using a registry pattern:Rate Limiting
Protect your endpoint with rate limiting:Best Practices
- Keep your public key in environment variables, never in source code
- Use the verification middleware on all Discord webhook routes
- Implement proper error handling and logging
- Add health check endpoints for monitoring
- Use environment-specific configurations
For production deployments, consider using a process manager like PM2 or containerizing with Docker.
Complete Working Example
Here’s the exact example from the repository:Next Steps
Message Components
Add interactive buttons and menus to your messages
Signature Verification
Deep dive into signature verification