Skip to content

Handle disable_on_timeout in DMs #2726

@tibue99

Description

@tibue99

Summary

In some cases, view buttons are not disabled in DMs when disable_on_timeout is set to True.

Reproduction Steps

  1. Run /party
  2. Click the button
  3. Wait for timeout

Minimal Reproducible Code

import discord

bot = discord.Bot()

class PartyButton(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=10, disable_on_timeout=True)

    @discord.ui.button(label="Party")
    async def party(self, button, interaction):
        await interaction.edit(content="🎉")


@bot.slash_command(
    contexts={discord.InteractionContextType.private_channel},
    integration_types={discord.IntegrationType.user_install},
)
async def party(ctx):
    await ctx.respond(view=PartyButton())

bot.run("")

Expected Results

Button gets disabled

Actual Results

Task exception was never retrieved
future: <Task finished name='discord-ui-view-timeout-37f1819640748e5c45353904a3edb8d9' coro=<View.on_timeout() done, defined at C:\Users\Timo\Desktop\cookie\.venv\Lib\site-packages\discord\ui\view.py:364> exception=Forbidden('403 Forbidden (error code: 50001): Missing Access')>
Traceback (most recent call last):
  File "C:\Users\Timo\Desktop\cookie\.venv\Lib\site-packages\discord\ui\view.py", line 381, in on_timeout
    m = await message.edit(view=self)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Timo\Desktop\cookie\.venv\Lib\site-packages\discord\message.py", line 1634, in edit
    data = await self._state.http.edit_message(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self.channel.id, self.id, **payload
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\Timo\Desktop\cookie\.venv\Lib\site-packages\discord\http.py", line 371, in request
    raise Forbidden(response, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

Intents

System Information

  • Python v3.13.0-final
  • py-cord v2.6.1-final
  • aiohttp v3.11.12
  • system info: Windows 11 10.0.26100

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

The on_timeout event contains the following code

            if not self._message or self._message.flags.ephemeral:
                message = self.parent
            else:
                message = self.message

The button would be disabled correctly if self.parent would be used for editing. However, due to the condition it uses self.message, which trows an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    unconfirmed bugA bug report that needs triaging

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions