Discord.py bot throwing interaction failure error on button clicks

I’m working on a Discord bot using discord.py and running into an issue where button interactions are failing. When users click my buttons, they see an interaction failed message but no errors show up in my console.

Here’s my current code:

class WelcomeView(discord.ui.View):
    @discord.ui.button(label="Accept", style=discord.ButtonStyle.green)
    async def accept_user(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message(content="User accepted!", ephemeral=True)
    
    @discord.ui.button(label="Reject", style=discord.ButtonStyle.danger)
    async def reject_user(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message(content="User rejected!")

@client.event
async def on_member_join(new_member: discord.Member):
    welcome_view = WelcomeView()
    
    target_role = discord.utils.get(new_member.guild.roles, name="NewMember")
    
    admin_channel_id = 1158716789103013898
    admin_channel = new_member.guild.get_channel(admin_channel_id)
    
    if admin_channel is not None:
        await new_member.add_roles(target_role)
        await admin_channel.send(f"{new_member} has joined! Please review:", view=welcome_view)
        await welcome_view.wait()
    else:
        print(f"Could not find channel with ID {admin_channel_id}")

The bot should automatically assign a role when someone joins and send a message to an admin channel with accept/reject buttons. The buttons appear correctly but clicking them causes the interaction to fail. Any ideas what might be causing this?

I’ve hit this exact issue before. The problem’s usually in how you handle the interaction response. Your code looks fine, but there’s likely a race condition with that await welcome_view.wait() line right after sending the message. The view becomes unresponsive before users can even click anything. Just remove that line - you don’t need to wait for the view to complete here. Also double-check your bot’s permissions in the admin channel. Make sure it has ‘Send Messages’ and ‘Use Slash Commands’. One more thing - verify your bot token has the right intents enabled, especially message content intent if you’re on newer discord.py versions.

this looks like a timeout problem. discord.py views timeout after 180 seconds by default, which breaks interactions. add timeout=None to your WelcomeView class or handle the timeout properly. also check that your bot has permissions for the channel it’s responding in.

This usually happens when your bot crashes or restarts between sending the view and getting the button click. When the bot restarts, all views become orphaned and can’t respond anymore. You’ll need persistent views with custom_id parameters and handle them in an on_interaction event. Also check for unhandled exceptions in your button callbacks - they might be failing silently. Wrap your button logic in try-except blocks to catch errors that aren’t showing up. I’ve seen this when the bot briefly loses connection to Discord during the interaction window.