When the view times out, I get this error:
Traceback (most recent call last):
File "c:\Users\Almos\PixelCards\DiscordBot.py", line 44, in on_timeout
await self.message.edit(content="You took too long to respond, action cancelled.", view=self)
AttributeError: 'View' object has no attribute 'message'
Code:
class View(discord.ui.View):
def __init__(self, banneduser):
self.banneduser = banneduser
self.done = False
super().__init__(timeout=15)
@discord.ui.button(label="Yes, proceed.", style=discord.ButtonStyle.green)
async def yes_callback(self, button, interaction):
for child in self.children:
child.disabled = True
embed = discord.Embed(title="User Banned", description=f"{self.banneduser} has been banned from trading.", color=discord.Colour.light_gray())
await interaction.response.edit_message(embed=embed, view=self)
self.done = True
@discord.ui.button(label="No, don't!", style=discord.ButtonStyle.danger)
async def no_callback(self, button, interaction):
for child in self.children:
child.disabled = True
embed = discord.Embed(title="Action cancelled.", description="You have cancelled this action. No changes have occured.", color=discord.Colour.light_gray())
await interaction.response.edit_message(embed=embed, view=self)
self.done = True
async def on_timeout(self):
if not self.done:
for child in self.children:
child.disabled = True
await self.message.edit(content="You took too long to respond, action cancelled.", view=self)