i have this discod button and i want it when it timeout i want the button to turn grey…
- User
i have this discod button and i want it when it timeout i want the button to turn grey so its not clickable anymore class Button2(View): def init(self, bot, link, user_id, *args, **kwargs): super().init(*args, **kwargs, timeout=60) self.bot = bot self.link_url = link self.user_id = user_id
@discord.ui.button(label="Bypass link", emoji="<:check:1157813295324069908>", style=discord.ButtonStyle.success, custom_id="prev") async def prev_button2(self, interaction: discord.Interaction, button: discord.ui.Button): if interaction.user.id != self.user_id: await interaction.response.send_message("You cannot use this button.", ephemeral=True) return try: await interaction.response.defer() embed = discord.Embed(title="<a:loading:1155221326420779042> Bypassing your link...", color=discord.Color.blurple()) await interaction.edit_original_response(embed=embed) await bypasser.bypass(self.bot, interaction, self.link_url) except Exception as e: traceback.print_exc() - Assistant
- User
why is this not working? like the making the button disabled and grey at timeout? class Button2(View): def init(self, bot, link, user_id, *args, **kwargs): super().init(*args, **kwargs, timeout=60) self.bot = bot self.link_url = link self.user_id = user_id self.interaction = None
@discord.ui.button(label="Bypass link", emoji="<:check:1157813295324069908>", style=discord.ButtonStyle.success, custom_id="prev") async def prev_button2(self, interaction: discord.Interaction, button: discord.ui.Button): self.interaction = interaction if interaction.user.id != self.user_id: await interaction.response.send_message("You cannot use this button.", ephemeral=True) return try: await interaction.response.defer() embed = discord.Embed(title="<a:loading:1155221326420779042> Bypassing your link...", color=discord.Color.blurple()) await interaction.edit_original_response(embed=embed) await bypasser.bypass(self.bot, interaction, self.link_url) except Exception as e: traceback.print_exc() async def on_timeout(self): for child in self.children: if isinstance(child, discord.ui.Button): child.disabled = True # Disable the button child.style = discord.ButtonStyle.gray # Change the style to grey await self.interaction.edit_original_response(view=self) - Assistant
- User
Task exception was never retrieved future: <Task finished name='discord-ui-view-timeout-f7c20de94a7c5cc16ada7a9985a004ce' coro=<Button2.on_timeout() done, defined at /home/container/src/discord/bypass_button.py:43> exception=AttributeError("'NoneType' object has no attribute 'edit'")> Traceback (most recent call last): File "/home/container/src/discord/bypass_button.py", line 48, in on_timeout await self.message.edit(view=self) ^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'edit'
- Assistant
- User
so nothing seemed to have worked, cant you do it with the self.bot? class Button2(View): def init(self, bot, link, user_id, *args, **kwargs): super().init(*args, **kwargs, timeout=60) self.bot = bot self.link_url = link self.user_id = user_id
@discord.ui.button(label="Bypass link", emoji="<:check:1157813295324069908>", style=discord.ButtonStyle.success, custom_id="prev") async def prev_button2(self, interaction: discord.Interaction, button: discord.ui.Button): if interaction.user.id != self.user_id: await interaction.response.send_message("You cannot use this button.", ephemeral=True) return try: await interaction.response.defer() embed = discord.Embed(title="<a:loading:1155221326420779042> Bypassing your link...", color=discord.Color.blurple()) await interaction.edit_original_response(embed=embed) await bypasser.bypass(self.bot, interaction, self.link_url) except Exception as e: traceback.print_exc() async def on_timeout(self): for child in self.children: if isinstance(child, discord.ui.Button): child.disabled = True # Disable the button child.style = discord.ButtonStyle.gray # Change the style to grey await self.message.edit(view=self) - Assistant