How Discord Interactions Work¶
Every click, pick, modal submit, and slash command reaches your bot as an interaction. Discord sets the rules for answering one, and CascadeUI follows them for you. This page explains those rules, so you know what the library does on your behalf and what changes when you call discord.py yourself.
Kinds of Interaction¶
| Interaction | Comes from | Where your code sees it |
|---|---|---|
| Application command | A slash command or a context menu | Your command, which builds the view and calls send() |
| Component | A click on a button, or a pick in a select | The component's callback |
| Modal submit | A submitted modal | The modal's callback |
| Autocomplete | Someone typing in a command option | Your command's autocomplete handler, without the library |
One Answer Within 3 Seconds¶
Discord waits 3 seconds for the bot to answer an interaction. Without an answer, a click shows "your bot didn't respond in time" under the message. An interaction takes exactly one answer:
| Answer | What the person sees |
|---|---|
interaction.response.defer() |
Nothing on a click or a submit, and "Bot is thinking..." on a slash command |
interaction.response.edit_message() |
The message the clicked component is on changes |
interaction.response.send_message() |
A reply |
interaction.response.send_modal() |
A modal, also as the answer to a modal's submission |
Once one is sent, interaction.response.is_done() returns True, and a second answer raises
discord.InteractionResponded.
In a view's callbacks, CascadeUI answers for you, and respond(), open_modal(), and safe_defer() answer the
way the moment allows. See Responding to Clicks.
A defer(thinking=True) on a click shows a new "thinking" message, which the next followup replaces. To show that
a button is working on the panel itself, wrap it with
with_loading_state():
the button shows a loading label, disabled, while its callback runs, and goes back after.
After the Answer¶
An interaction can still send messages for 15 minutes after it arrived. interaction.followup.send() posts more
replies, and interaction.edit_original_response() edits the answer. A followup is public unless you pass
ephemeral=True, except the first one after a slash command's defer: it takes the place of the "thinking" message
and keeps the defer's visibility, whatever it asks.
A slow send() meets that rule on its own: when the view's
on_load() is still running at 2.5 seconds, the library defers the command, and the
panel goes out as that first followup.
CascadeUI works with that rule in two places. When the library deferred a slow public send itself and then refuses it privately (an instance limit, a full panel), or the command then sends a panel privately, it deletes its own "thinking" message first, so the reply stays private. A panel sent after a defer of your own gets the defer's visibility, and the view treats it as what Discord posted, with a warning naming the defer.
respond() sends the answer when
the interaction has none yet, and a followup when it does.
Two Ways to Edit a Message¶
| Through | Works for | Used for |
|---|---|---|
The interaction: edit_message(), edit_original_response() |
15 minutes from that interaction | Answering a click |
The channel: message.edit() |
As long as the message exists | Every other edit of a public panel |
CascadeUI uses both:
- A
refresh()that answers a click edits the message as the answer, one request for both. - Any other redraw of a public panel goes through the channel once the view has read its message back, so it works however long ago the panel was sent.
- If Discord is slow to accept the one-request edit, the library stops waiting before the 3 seconds run out, acknowledges the click, and sends the edit again. See A Click Updates Late.
A callback whose work takes more than a
second or so can acknowledge the click at once with safe_defer(). Its
refresh() then edits the message in a request of its own.
Ephemeral Messages¶
| Rule | What it means |
|---|---|
| Not readable through the channel | channel.fetch_message() cannot find one, so the view keeps the message send() returned |
| Edited and deleted only through an interaction | The command's, for 15 minutes, or a click's |
| No reactions | Discord refuses a reaction on one |
| A followup is public unless told otherwise | Pass ephemeral=True on each one |
What the library does when the 15 minutes run out is on Ephemeral Views.
Embeds or Components¶
A StatefulView sends an embed with buttons under it. A StatefulLayoutView's components are the whole message.
That changes what an edit can do:
- A
StatefulViewredraws its embed by passing it torefresh():refresh(embed=...). AStatefulLayoutViewpasses nothing, since the components it redraws are its content. - Closing a
StatefulViewcan remove its buttons and keep the embed. AStatefulLayoutViewcannot remove its components, which would leave a message with nothing in it, so its close disables them instead. See Closing a View. - Moving between the two needs a new message: see Between the Two Kinds of View.
Related¶
- Responding to Clicks: how the library answers each click.
- Ephemeral Views: the 15-minute limit on ephemeral panels.
- Lifecycle and Closing: what a closed panel shows.
- Discord Limits: every number Discord sets.