From 0d9021626df9284baacc4754f3ab0fcc5430e6bf Mon Sep 17 00:00:00 2001 From: Soheab_ <33902984+Soheab@users.noreply.github.com> Date: Fri, 21 Feb 2025 16:19:21 +0100 Subject: [PATCH 1/3] Improve on_timeout fix --- docs/faq.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/faq.rst b/docs/faq.rst index 0cd8b8ad6b8c..d7e913126d56 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -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. @@ -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: @@ -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 From 8e697326998fad5da84ec168b6fefc60c5cec19a Mon Sep 17 00:00:00 2001 From: Soheab <33902984+Soheab@users.noreply.github.com> Date: Fri, 21 Feb 2025 19:36:23 +0100 Subject: [PATCH 2/3] Update docs/faq.rst Co-authored-by: DA344 <108473820+DA-344@users.noreply.github.com> --- docs/faq.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/faq.rst b/docs/faq.rst index d7e913126d56..1573478ca8fd 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -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, 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. +Application commands, when you respond with :meth:`InteractionResponse.send_message`, return 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: From 28f14039d9c6b9033526196ebd0f3342e5c70338 Mon Sep 17 00:00:00 2001 From: Soheab <33902984+Soheab@users.noreply.github.com> Date: Mon, 24 Feb 2025 11:19:28 +0100 Subject: [PATCH 3/3] Update docs/faq.rst Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com> --- docs/faq.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/faq.rst b/docs/faq.rst index 1573478ca8fd..16d03362abef 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -481,8 +481,8 @@ Putting it all together, using the previous view definition: # Step 1 resource = callback.resource - # making sure it's a message - if isinstance(resource, discord.Message): + # making sure it's an interaction response message + if isinstance(resource, discord.InteractionMessage): view.message = resource