Auf Interaktionen antworten
Jede Nutzung eines Slash-Befehls, Menübefehls, einer Schaltfläche, eines Auswahlmenüs, Formulars oder der Autovervollständigung erreicht deinen Bot als Interaktion. Diese Seite zeigt, wie du rechtzeitig antwortest.
Das brauchst du
Eine laufende Gateway-Verbindung mit dem Intent INTERACTIONS oder eine HTTP-Adresse. Befehle funktionieren in Serverkanälen und, für die globalen Befehle des Bots ohne Serverberechtigung, in einer Direktnachricht mit ihm. Schaltflächen, Auswahlmenüs und Formulare funktionieren in dieser Direktnachricht auch; server_id und member fehlen dann.
Die Zeitlimits
| Limit | Zeit | Was danach passiert |
|---|---|---|
| Erste Antwort | 3 Sekunden | Die Person sieht, dass der Bot nicht geantwortet hat. Eine späte Antwort bekommt InteractionExpired |
| Änderungen und Folgenachrichten | 15 Minuten | Das Token hört auf: InteractionExpired oder UnknownInteraction |
Das Ereignis trägt beide als respond_by und expires_at. Richte dich nach den Zeiten des Ereignisses, nicht nach deiner Uhr.
Dauert die Arbeit mehr als einen Moment, antworte zuerst DeferredMessage. Das zeigt „denkt nach“ und gibt dir die 15 Minuten.
Ist dein Bot nicht verbunden, wenn jemand einen Befehl nutzt, geht das Ereignis verloren, und die Person sieht den Fehler nach 3 Sekunden.
Das Ereignis
{
"type": "InteractionCreate",
"interaction": {
"_id": "01JC0000000000000000000013",
"version": 1,
"application_id": "01JC0000000000000000000001",
"type": "Command",
"token": "YOUR_INTERACTION_TOKEN",
"user": { "_id": "01JC0000000000000000000012", "username": "example_user" },
"member": { "_id": { "server": "01JC0000000000000000000003", "user": "01JC0000000000000000000012" } },
"server_id": "01JC0000000000000000000003",
"channel_id": "01JC0000000000000000000004",
"user_permissions_string": "2276038022144",
"app_permissions_string": "4398045478879",
"locale": "ar",
"command": { "id": "01JC0000000000000000000014", "name": "ping", "type": "ChatInput", "options": [] },
"respond_by": "2026-11-06T07:04:12.432Z",
"expires_at": "2026-11-06T07:19:09.432Z"
}
}| Feld | Bedeutung |
|---|---|
type | Command, Component, ModalSubmit oder Autocomplete |
token | Gilt nur für diese Interaktion. Behandle es bis expires_at wie ein Passwort |
user, member | Wer es getan hat |
user_permissions_string | Ihre Berechtigungen in diesem Kanal. Nimm das in JavaScript, nicht user_permissions |
app_permissions_string | Die Berechtigungen deines Bots in diesem Kanal |
locale | Ihre Sprache, falls die App sie gesendet hat |
command | Bei Command und Autocomplete: name, options, resolved, target_id, focused |
component | Bei Component: custom_id, component_type, values, resolved |
modal | Bei ModalSubmit: custom_id, fields, resolved |
message_id | Die Nachricht, auf der die Komponente sitzt |
message_ephemeral | true, wenn diese Nachricht privat ist |
Die Berechtigungszahlen sind zu groß für eine JavaScript-Zahl, also lies sie als BigInt:
const canTimeout = (BigInt(interaction.user_permissions_string) >> 8n) & 1n;Antworten
Sende eine erste Antwort. Es braucht keinen Token-Header: Der Pfad enthält das Token.
curl -X POST "https://api.zrzur.com/interactions/INTERACTION_ID/YOUR_INTERACTION_TOKEN/callback" \
-H "content-type: application/json" \
-d '{ "type": "Message", "data": { "content": "Pong!" } }'Antwort type | Wann | Text |
|---|---|---|
Message | Jetzt antworten | data |
DeferredMessage | Die Arbeit dauert länger als 3 Sekunden. Zeigt „denkt nach“ | data.ephemeral, wenn es privat bleibt |
UpdateMessage | Schaltflächen und Menüs: die Nachricht der Komponente ändern | data |
DeferredUpdate | Schaltflächen und Menüs: jetzt bestätigen, Nachricht später ändern | keiner |
Modal | Ein Formular öffnen. Nicht als Antwort auf ein Formular oder Autovervollständigung | modal |
AutocompleteResult | Vorschläge. Die einzige Antwort auf Autocomplete | choices, bis zu 25 |
data nimmt content, embeds, components und ephemeral. Zweimal antworten ergibt InteractionAlreadyAcknowledged.
Private Antworten
"ephemeral": true zeigt eine Antwort nur dieser Person. Sie wird nie im Kanal gespeichert und verschwindet beim Neuladen. Die Wahl fällt einmal: Eine aufgeschobene Antwort bleibt so privat, wie du beim Aufschieben gesagt hast.
Aufgeschobene Antworten
# 1. within 3 seconds
curl -X POST "https://api.zrzur.com/interactions/INTERACTION_ID/YOUR_INTERACTION_TOKEN/callback" \
-H "content-type: application/json" \
-d '{ "type": "DeferredMessage", "data": { "ephemeral": true } }'
# 2. within 15 minutes
curl -X PATCH "https://api.zrzur.com/interactions/INTERACTION_ID/YOUR_INTERACTION_TOKEN/original" \
-H "content-type: application/json" \
-d '{ "content": "Done." }'Folgenachrichten
Nach der ersten Antwort kannst du bis zu 5 weitere Nachrichten zur selben Interaktion senden, bis das Token endet:
curl -X POST "https://api.zrzur.com/interactions/INTERACTION_ID/YOUR_INTERACTION_TOKEN/followups" \
-H "content-type: application/json" \
-d '{ "content": "One more thing.", "ephemeral": true }'Die Antwort enthält die _id der neuen Nachricht. Eine Folgenachricht hat ihre eigene ephemeral-Wahl und kann nicht nach einer Modal-Antwort kommen.
| Um | Route |
|---|---|
| Die erste Antwort zu ändern | PATCH /interactions/{interaction_id}/{token}/original |
| Die erste Antwort zu löschen | DELETE /interactions/{interaction_id}/{token}/original |
| Eine Folgenachricht zu ändern | PATCH /interactions/{interaction_id}/{token}/messages/{message_id} |
| Eine Folgenachricht zu löschen | DELETE /interactions/{interaction_id}/{token}/messages/{message_id} |
Autovervollständigung
Eine Option mit "autocomplete": true fragt deinen Bot beim Tippen nach Vorschlägen. command.focused nennt die Option, und ihr value enthält den bisherigen Text, bis zu 100 Zeichen.
{
"type": "AutocompleteResult",
"choices": [{ "name": "Apricot", "value": "apricot" }]
}Antworte schnell, denn jeder Tastendruck kann eine Anfrage senden. Eine Autocomplete-Interaktion nimmt nur diese Antwort, und keine andere nimmt sie.
Häufige Fehler
| Fehler | Ursache | Lösung |
|---|---|---|
InteractionExpired | Über die 3 Sekunden oder die 15 Minuten | Zuerst aufschieben |
InteractionAlreadyAcknowledged | Eine zweite erste Antwort | Folgenachricht oder Änderung |
InvalidOperation | Die Antwort passt nicht, etwa UpdateMessage auf einen Befehl | Prüfe die Tabelle oben |
TooManyFollowups | Mehr als 5 | Ändere stattdessen eine Nachricht |
UnknownInteraction | Falsche ID oder falsches Token | Nimm die Werte des Ereignisses |
Referenz
GET /applications/{application_id}/commands
List Global Commands. Commands of this application available in every server it is installed in.
Ratenlimit: any_dlta, 20 / 10 s
POST /applications/{application_id}/commands
Create Global Command. Register a new command. A command with the same type and name is a conflict.
Ratenlimit: any_dlta, 20 / 10 s
PUT /applications/{application_id}/commands
Sync Global Commands. Replace every global command with the given list, matched by type and name. The list is validated as a whole before anything changes.
Ratenlimit: any_dlta, 20 / 10 s
DELETE /applications/{application_id}/commands/{command_id}
Delete Global Command.
Ratenlimit: any_dlta, 20 / 10 s
GET /applications/{application_id}/commands/{command_id}
Fetch Global Command.
Ratenlimit: any_dlta, 20 / 10 s
PATCH /applications/{application_id}/commands/{command_id}
Edit Global Command.
Ratenlimit: any_dlta, 20 / 10 s
GET /applications/{application_id}/servers/{server_id}/commands
List Server Commands. Commands of this application limited to one server it is installed in.
Ratenlimit: any_dlta, 20 / 10 s
POST /applications/{application_id}/servers/{server_id}/commands
Create Server Command.
Ratenlimit: any_dlta, 20 / 10 s
PUT /applications/{application_id}/servers/{server_id}/commands
Sync Server Commands.
Ratenlimit: any_dlta, 20 / 10 s
DELETE /applications/{application_id}/servers/{server_id}/commands/{command_id}
Delete Server Command.
Ratenlimit: any_dlta, 20 / 10 s
GET /applications/{application_id}/servers/{server_id}/commands/{command_id}
Fetch Server Command.
Ratenlimit: any_dlta, 20 / 10 s
PATCH /applications/{application_id}/servers/{server_id}/commands/{command_id}
Edit Server Command.
Ratenlimit: any_dlta, 20 / 10 s
DELETE /channels/{target}/messages/{msg}/reactions
Remove All Reactions from Message. Remove your own, someone else's or all of a given reaction.
Requires ManageMessages permission.
Berechtigungen: Channel:ManageMessages · Ratenlimit: channels, 15 / 10 s
DELETE /channels/{target}/messages/{msg}/reactions/{emoji}
Remove Reaction(s) to Message. Remove your own, someone else's or all of a given reaction.
Requires ManageMessages if changing others' reactions.
Berechtigungen: Channel:React, Channel:ManageMessages · Ratenlimit: channels, 15 / 10 s
PUT /channels/{target}/messages/{msg}/reactions/{emoji}
Add Reaction to Message. React to a given message.
Berechtigungen: Channel:React · Ratenlimit: channels, 15 / 10 s
POST /interactions
Create Interaction. Use an application command, a component on a bot's message, or submit a form the bot opened. The server checks every value and permission, then sends the interaction to the bot only. The answer arrives as InteractionStateUpdate plus a channel message, a message update, EphemeralMessageCreate or InteractionModal, for this user.
Sending the same nonce again returns the first interaction.
Für Bots nicht verfügbar.
Ratenlimit: interactions, 15 / 10 s
POST /interactions/{interaction_id}/{token}/callback
Respond to Interaction. First answer of the bot, authenticated by the interaction token. It must arrive before respond_by and can only happen once.
- Message: reply now; data.ephemeral makes it visible to the invoking user only, and it is never stored as a channel message. - DeferredMessage: show that the bot is working; finish later with PATCH /interactions/<id>/<token>/original before the token expires. - UpdateMessage / DeferredUpdate (components and forms opened from one): change the message the component is on, now or later. - Modal: open a form for the user (not as an answer to a form). - AutocompleteResult (autocomplete only): up to 25 suggestions.
Ratenlimit: interaction_callbacks, 10 / 10 s
POST /interactions/{interaction_id}/{token}/followups
Send Follow-up. Another message for the same interaction, after the first answer (or while it is deferred). At most 5 per interaction.
Ratenlimit: interaction_callbacks, 10 / 10 s
DELETE /interactions/{interaction_id}/{token}/messages/{message_id}
Delete Interaction Message. Delete the first answer or a follow-up by its message id. For private messages the invoking user's clients receive EphemeralMessageDelete.
Ratenlimit: interaction_callbacks, 10 / 10 s
PATCH /interactions/{interaction_id}/{token}/messages/{message_id}
Edit Interaction Message. Edit the first answer or a follow-up by its message id.
Ratenlimit: interaction_callbacks, 10 / 10 s
DELETE /interactions/{interaction_id}/{token}/original
Delete Original Response.
Ratenlimit: interaction_callbacks, 10 / 10 s
PATCH /interactions/{interaction_id}/{token}/original
Edit Original Response. Finish a deferred interaction, or edit the answer, until the token expires. After UpdateMessage or DeferredUpdate this edits the component's message.
Ratenlimit: interaction_callbacks, 10 / 10 s
POST /interactions/autocomplete
Request Autocomplete. Ask the bot for suggestions while the user types into an option with autocomplete. The suggestions arrive as InteractionAutocompleteResult. Clients should wait for a pause in typing and drop answers to older requests.
Für Bots nicht verfügbar.
Ratenlimit: interactions_autocomplete, 30 / 10 s
GET /servers/{server_id}/applications
List Server Apps. Apps installed in this server, who installed them and with which permissions.
Ratenlimit: servers, 5 / 10 s
DELETE /servers/{server_id}/applications/{application_id}
Uninstall App. Remove an app's bot from the server: its membership, its managed role and its install record go; its server-scoped commands stop showing.
Ratenlimit: servers, 5 / 10 s
GET /servers/{server_id}/applications/{application_id}/commands
Fetch App Commands In Server. Every command of an app that works in this server, global and limited to this server, without any filtering: for the people who manage the app's rules. Needs Manage Server.
Ratenlimit: servers, 5 / 10 s
PUT /servers/{server_id}/applications/{application_id}/commands/{command_id}/permissions
Edit Command Permissions. Replace the rules for one command in this server; they come before the app's rules. An empty list removes them. Needs Manage Server and Manage Roles; see the module documentation for which rules an editor may write.
Ratenlimit: servers, 5 / 10 s
GET /servers/{server_id}/applications/{application_id}/permissions
Fetch Command Permissions. The rules set in this server for an app: the whole app (no command_id) and each command that has its own.
Ratenlimit: servers, 5 / 10 s
PUT /servers/{server_id}/applications/{application_id}/permissions
Edit App Permissions. Replace the rules for the whole app in this server. An empty list removes them. Needs Manage Server and Manage Roles; see the module documentation for which rules an editor may write.
Ratenlimit: servers, 5 / 10 s
GET /servers/{server_id}/commands
Fetch Server Commands. Commands a member can pick from in this server: those of every bot installed here, global or limited to this server. Commands that need server permissions the member lacks, or that the server's command permission rules keep from them, are left out. With channel, the channel rules count too (a thread or forum post uses its channel's); the channel is checked again when a command is used.
Ratenlimit: servers, 5 / 10 s