Discord bot button interaction not updating message properly

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?

Had the same issue building a multi-step form bot. You’re probably creating new View instances for each interaction without managing their lifecycle properly. Discord limits how long interactions can stay alive, and chaining multiple edit_message calls causes timeouts.

What fixed it for me: use one persistent View class that handles all states instead of creating new ones each time. Track which phase you’re in with a state variable and update components accordingly. Also, don’t call both response.edit_message and followup.edit_message in the same chain - that’ll throw the “Interaction failed” error every time.

Check if you’re hitting the 15-minute interaction token expiry too. If users take too long between steps, the final interaction might use an expired token.

Yeah, classic discord.py gotcha. You’re nesting too many interaction responses - after 3-4 chained edit_message calls the token goes stale. Try await ctx.edit_original_response() instead of ctx.response.edit_message() for that final button. Works way better than dealing with followup messages.

This happens because Discord only lets you call response.edit_message() once per interaction chain. By the third question, you’ve already used up the interaction token from previous responses. Don’t use ctx.response.edit_message() in your finish callback - switch to ctx.followup.edit_message() or even better, use interaction.edit_original_response(). The original response method gets around the token limit since it references the initial interaction. I hit this same issue with a survey bot and fixed it by checking interaction.response.is_done() first, then picking between response or followup methods. Also bump up the timeout on your View classes - 180 seconds doesn’t give users much time to think between questions.