Documentation
¶
Overview ¶
This example runs a bot in Discord's "webhook interactions" mode: instead of keeping a gateway websocket connection open, an HTTP server receives interaction POSTs from Discord and answers them directly in the HTTP response. The bot works without any persistent connection to Discord.
Setup:
- Create an application in the Discord developer portal.
- Copy the public key from the "General Information" page into the INTERACTIONS_PUBLIC_KEY environment variable.
- Set DISCORD_TOKEN to a bot token. It is only used for REST calls made on top of received interactions (ReplyEphemeral below); the inline responses need no token at all.
- Expose the server through a public HTTPS URL (Discord requires HTTPS; use a reverse proxy or a tunnel such as ngrok for local testing) and set the "Interactions Endpoint URL" in the developer portal to https://your.host/interactions. Discord verifies the URL by sending a PING request, which the InteractionServer answers automatically.
Optionally set DISCORD_APP_ID (and DISCORD_GUILD_ID for instant guild scope) to register the two slash commands of this example on startup.