Interactions and deferred answers
Every command run, click and modal submit is an interaction with an id and a token. You answer it once, within 15 minutes, and then may follow up and edit.
Types
Interaction type | When |
|---|---|
2 | a slash command ran (data: id, name, options) |
3 | a component was used (data: custom_id, component_type, values, resolved; message is the message it is on) |
5 | a modal was submitted (data: custom_id, components; message when the modal came from a component) |
Every interaction carries the member who caused it in member.user.
The first answer
POST /api/bot/v1/interactions/{id}/{token}/callback:
Callback type | Effect | Allowed for |
|---|---|---|
4 | post a message (data: content, embeds, components, flags) | 2, 3, 5 |
5 | acknowledge; the message follows (PATCH @original or follow-ups) | 2, 3, 5 |
6 | acknowledge a click without changing anything yet | 3 |
7 | update the message the component is on (absent fields stay) | 3 |
9 | open a modal | 2, 3 |
Callback 5 or 6 also tells the member that the bot is on it, so the app says the bot is taking longer instead of inviting another click.
Deferred answers
Slow work? Acknowledge with type 5 first, then deliver:
await i.deferReply()
const result = await somethingSlow()
await i.editReply(`Done: ${result}`)
if err := i.DeferReply(ctx, false); err != nil {
return err
}
text := "Done"
_, err := i.EditReply(ctx, mnema.Edit{Content: &text})
After the first answer
POST .../followupssends more messages: up to 5 messages in total per interaction (callback4, the message posted after5, and the follow-ups).PATCH .../messages/@originaledits the first response, and after a type5posts it.DELETE .../messages/@originaldeletes it.- Follow-ups and
@originaledits work for the same 15 minutes.
Ephemeral answers
"flags": 64 shows the answer to the member who ran the command only. It is delivered to that member's open sessions as a private note in the channel and never stored: if the member is offline, they miss it. Flags are taken by callback 4, callback 5 and follow-ups; the first answer decides whether a reply is ephemeral, so an @original edit refuses flags.
Limits and lifetime
- The first answer must come within 15 minutes.
- Interactions live in the server's memory: a restart within those 15 minutes makes the token unknown (
404). Components are not affected: theircustom_idis stored with the message, and every click is a new interaction. - Whatever closes a bot's connections (disabling it, revoking a token, changing its intents) also ends its pending interactions.
- The bot needs Send messages in the channel when it responds. Messages a response posts follow the same mention rules as a post: see
allowed_mentions.