#AttributeError 'View' object has no attribute 'message'

1 messages · Page 1 of 1 (latest)

novel matrix
#

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)

silk wigeon
#

self is the view as it says

#

b!rtfm pycord view

silk wigeon
#

b!rtfm pycord view.message

bronze nacelleBOT
novel matrix
#

why does the guide say this then?

novel matrix
novel matrix
agile marten
#

hmm

novel matrix
#

i can edit the message from the button callbacks but idk how to do it from the timeout

keen shadow
#

I guess there's a bad example in the guide

silk wigeon
#

interaction.response.edit_message

#

b!rtfm interaction.response

#

b!rtfm pycord interaction.response

bronze nacelleBOT
novel matrix
silk wigeon
novel matrix
#

how do i pass interaction to the timeout method

silk wigeon
#

Docs are useful yk

novel matrix
#

oh

#

i see

#

aight

#

so ur not supposed to do it inside the view

#

got it

agile marten
# novel matrix got it

since its on a .respond can't you just try

await ctx.edit(content="You took too long to respond, action cancelled.",view=self)
# instead of
await self.message.edit
#

It's what i use on a / command to edit the original message

silk wigeon
#

It's not a slash command.

agile marten
novel matrix
#

oh and another question

#

how do i know who pressed the button

keen shadow
#

interaction.user

novel matrix
#

thx

#

you can close this now