Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve on_timeout FAQ #10110

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ How can I disable all items on timeout?

This requires three steps.

1. Attach a message to the :class:`~discord.ui.View` using either the return type of :meth:`~abc.Messageable.send` or retrieving it via :meth:`Interaction.original_response`.
1. Attach a message to the :class:`~discord.ui.View` using either the return type of :meth:`~abc.Messageable.send` or retrieving it via :attr:`InteractionCallbackResponse.resource`.
2. Inside :meth:`~ui.View.on_timeout`, loop over all items inside the view and mark them disabled.
3. Edit the message we retrieved in step 1 with the newly modified view.

Expand Down Expand Up @@ -467,7 +467,7 @@ Putting it all together, we can do this in a text command:
# Step 1
view.message = await ctx.send('Press me!', view=view)

Application commands do not return a message when you respond with :meth:`InteractionResponse.send_message`, therefore in order to reliably do this we should retrieve the message using :meth:`Interaction.original_response`.
Application commands, when you respond with :meth:`InteractionResponse.send_message`, returns an instance of :class:`InteractionCallbackResponse` which contains the message you sent. This is the message you should attach to the view.

Putting it all together, using the previous view definition:

Expand All @@ -477,10 +477,13 @@ Putting it all together, using the previous view definition:
async def more_timeout_example(interaction):
"""Another example to showcase disabling buttons on timing out"""
view = MyView()
await interaction.response.send_message('Press me!', view=view)
callback = await interaction.response.send_message('Press me!', view=view)

# Step 1
view.message = await interaction.original_response()
resource = callback.resource
# making sure it's a message
if isinstance(resource, discord.Message):
view.message = resource


Application Commands
Expand Down
Loading