so i have this piece of discord bot, i want to check if that interaction has a view, if…
- User
so i have this piece of discord bot, i want to check if that interaction has a view, if the view of the interaction is none then dont change the view if its not none and change the view await self.interaction.edit_original_response(view=Disabled())
- Assistant
Sure, I understand your need to check if the interaction has a view and to proceed accordingly. To accomplish this, you can follow this approach in your Discord bot code:
- First, determine if the interaction has a view.
- User
fix the code in the on timeout function class Button2(View): def init(self, bot, interaction, link, user_id, *args, **kwargs): super().init(*args, **kwargs, timeout=60) self.bot = bot self.interaction = interaction 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): try: if self.interaction.view is not None: await self.interaction.edit_original_response(view=Disabled()) except Exception: traceback.print_exec() - Assistant
- User
another way
- Assistant
- User
bro i just want to check if the original message's view is not None and edit it with the view=discord()
- Assistant
- User
Task exception was never retrieved future: <Task finished name='discord-ui-view-timeout-ed4135a252764eb9fafcda9d0af7d237' coro=<Button2.on_timeout() done, defined at /home/container/src/discord/bypass_button.py:42> exception=AttributeError("module 'traceback' has no attribute 'print_exec'")> Traceback (most recent call last): File "/home/container/src/discord/bypass_button.py", line 44, in on_timeout original_message = await self.interaction.original_message() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Interaction' object has no attribute 'original_message'
- Assistant