Repository: Pycord-Development/pycord

Issue:
`disable_on_timeout` not working as expected for ephemeral messages
### Summary

`on_timeout` throws an error for ephemeral messages, if the interaction has already been responded to.

### Reproduction Steps

1. Run the code below
2. Run /test
3. Click the button
4. Wait for the timeout

### Minimal Reproducible Code

```python
import discord

bot = discord.Bot(intents=discord.Intents.default())


class View(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=5, disable_on_timeout=True)

    @discord.ui.button(label='Click')
    async def button_callback(self, button, interaction):
        await interaction.response.send_message('Click!')


@bot.slash_command()
async def test(ctx):
    await ctx.respond(view=View(), ephemeral=True)


bot.run("")
```


### Expected Results

Button gets disabled

### Actual Results

```
Task exception was never retrieved
future: <Task finished name='discord-ui-view-timeout-5c120900490a1504623a8aed0a874bb7' coro=<View.on_timeout() done, defined at C:\Users\Timo\Desktop\pythonProject\venv\lib\site-packages\discord\ui\view.py:364> exception=NotFound('404 Not Found (error code: 10008): Unknown Message')>
Traceback (most recent call last):
  File "C:\Users\Timo\Desktop\pythonProject\venv\lib\site-packages\discord\ui\view.py", line 373, in on_timeout
    m = await message.edit(view=self)
  File "C:\Users\Timo\Desktop\pythonProject\venv\lib\site-packages\discord\message.py", line 1479, in edit
    data = await self._state.http.edit_message(
  File "C:\Users\Timo\Desktop\pythonProject\venv\lib\site-packages\discord\http.py", line 367, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message
```

### Intents

discord.Intents.default()

### System Information

- Python v3.10.9-final
- py-cord v2.4.1-final
- aiohttp v3.9.1
- system info: Windows 10 10.0.22631

### Checklist

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

### Additional Context

I was able to resolve this by switching `self._message` and `self.parent` in `on_timeout`, I could open a PRfor that.


Discussion:
Feel free to pr it. We still can't release tho 
When switching `self._message` and `self.parent`, a `NotFound` error will be raised in case the message is non-ephemeral and deleted before the timeout event.
Not sure how this can be solved without try-except, someone else could take over the PR.

Resolving patch:
diff --git a/discord/ui/view.py b/discord/ui/view.py
--- a/discord/ui/view.py
+++ b/discord/ui/view.py
@@ -368,7 +368,12 @@ async def on_timeout(self) -> None:
         """
         if self.disable_on_timeout:
             self.disable_all_items()
-            message = self._message or self.parent
+
+            if not self._message or self._message.flags.ephemeral:
+                message = self.parent
+            else:
+                message = self.message
+
             if message:
                 m = await message.edit(view=self)
                 if m:


Test patch: