I’m working with discord.py and having trouble with button interactions. My bot sends messages with select menus and buttons, but after going through multiple interactions, the final button click fails to update the message and shows an “Interaction failed” error.
async def start_quiz(interaction: discord.Interaction):
class StartButton(discord.ui.View):
@discord.ui.button(label="Begin", style=discord.ButtonStyle.green)
async def start_callback(self, interaction: discord.Interaction, button):
await show_question(interaction, first_question, user_id)
await interaction.response.send_message(embed=welcome_embed, view=StartButton(), ephemeral=True)
async def show_question(interaction: discord.Interaction, question_data: dict, user_id: int):
class QuestionSelect(discord.ui.View):
@discord.ui.select(...)
async def answer_callback(self, ctx: discord.Interaction, select):
if question_data == first_question:
await show_question(ctx, second_question, user_id)
elif question_data == second_question:
await show_question(ctx, third_question, user_id)
elif question_data == third_question:
await show_final_result(ctx, user_id)
await interaction.response.edit_message(embed=question_embed, view=QuestionSelect())
async def show_final_result(interaction: discord.Interaction, user_id: int):
class FinishButton(discord.ui.View):
@discord.ui.button(label="Finish", style=discord.ButtonStyle.red)
async def finish_callback(self, ctx: discord.Interaction, button):
final_embed = discord.Embed(...)
await ctx.response.edit_message(embed=final_embed, view=None)
result_embed = discord.Embed(...)
await interaction.response.edit_message(embed=result_embed, view=FinishButton())
The last button click in finish_callback is where it breaks. I’ve tried switching between different interaction objects but nothing seems to work. Any ideas what might be causing this?