Skip to main content
Connectors

Discord

Talk to an agent with a slash command in Discord.

DiscordRoute/discord/interactionsAgent Actorreceive, replywebhookreceive()edit the deferred reply

Quickstart

Create a Discord application

In the Discord Developer Portal, create an application. Copy its application ID and public key, and create a bot token.

Register the command

Register an /ask command with a prompt option:

curl -X PUT "https://discord.com/api/v10/applications/$DISCORD_APPLICATION_ID/commands" \
  -H "Authorization: Bot $DISCORD_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '[{"name":"ask","description":"Ask the agent","options":[{"type":3,"name":"prompt","description":"What to ask","required":true}]}]'

Install the application to your server with the applications.commands scope.

Add the route

npm add @rivet-dev/pi rivetkit hono discord-interactions

Run the server with any runtime that serves a fetch handler, for example npx srvx --import tsx server.ts. See HTTP Server.

Set the environment

DISCORD_PUBLIC_KEY=...
ANTHROPIC_API_KEY=sk-ant-...

Set the interactions endpoint

Under General Information, set the interactions endpoint URL to https://<your-worker>/discord/interactions. Discord sends a ping, which the route answers. Run /ask in a channel.

How it works

  • The route verifies Discord’s Ed25519 signature against the raw body with the application’s public key.
  • Each Discord channel gets its own agent. Every /ask in the channel continues the same session.
  • Discord expects a response within three seconds and an agent run takes longer, so the route hands the command to the agent’s receive action and defers the reply. receive schedules reply, which prompts the agent and edits the deferred message. Interaction tokens stay valid for 15 minutes, and a message holds up to 2,000 characters. The schedule is saved with the agent, so the reply still runs if the request that delivered the message goes away.

Configure

VariablePurpose
DISCORD_PUBLIC_KEYRequired. Verifies that requests come from Discord.
DISCORD_APPLICATION_IDRegisters the command. Not needed by the server.
DISCORD_BOT_TOKENRegisters the command. Not needed by the server.
ANTHROPIC_API_KEYRequired. The agent’s model key. See API Keys.

Supported events

Discord interactionWebhook pathWhat the route does
PING/discord/interactionsAnswers Discord’s endpoint check.
Application command /ask/discord/interactionsHands the command to the channel’s agent and defers. The agent edits the reply.