Skip to content

Instantly share code, notes, and snippets.

@cibere
Created September 10, 2023 16:11
Show Gist options
  • Save cibere/7e1356575780e716d2e3a23ea2bcf6da to your computer and use it in GitHub Desktop.
Save cibere/7e1356575780e716d2e3a23ea2bcf6da to your computer and use it in GitHub Desktop.
Discord.py defer response

The Defer Response

The defer response, defers the interaction response. This is typically used when the interaction is acknowledged and an optional secondary action will be done later. When deferring, you get up to 15 minutes to respond instead of the normal 3 seconds.

This response is only supported if the interaction is an application command, component/view, or a modal.

Followups

Because deferring counts as a response, your can't use the typical InteractionResponse methods. Here are a list of substitutions that you can use.

Send Message

To send a message after the initial response, we can send a followup via Interaction.followup. This returns a Webhook, so we can use Webhook.send to send a message. Example:

await interaction.followup.send(...)

also, unlike response.send_message, followup.send DOES return the message object (if you set wait to True)

Note: when deferring in an app_command or modal, your first followup will respect the ephemeral setting set when deferring, and all other followups will be independent

Edit Response

To edit the initial response, we can use Interaction.edit_original_response.

Note: If the response was defer, you set thinking to False, and the interaction came from a component, this will edit the message the component is on.

Delete Response

To delete the initial response, we can use delete_original_response.

Note: If the response was defer, you set thinking to False, and the interaction came from a component, this will delete the message the component is on.

Send Modal

Sending a modal can only be done via the response. If you need more than 3 seconds to prepare a modal, consider sending a button that lets your user open the modal after preparing it.

Defer

15 minutes is the max amount of time that you can get. You can not defer a second time for another 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment