Encountering 'interaction failed' error when clicking button in my Discord bot

I’ve set up a Discord bot that reacts to commands and includes buttons for user input. However, when users click the button, an error message pops up stating that the interaction failed. Here’s a snippet of my code:

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix="$", intents=intents)

@bot.event
async def on_ready():
    print(f'{bot.user.name} is up and running!')

@bot.command()
async def suggestion(ctx):
    await ctx.send("Press the button below to submit your suggestion.", view=SuggestionView())

class SuggestionView(discord.ui.View):
    @discord.ui.button(label="Submit Your Suggestion", style=discord.ButtonStyle.primary)
    async def submit_suggestion(self, button: discord.ui.Button, interaction: discord.Interaction):
        try:
            await interaction.response.send_modal(SuggestionModal())
        except Exception as e:
            print(f"Error showing modal: {e}")
            await interaction.response.send_message("There was an issue trying to display the modal.", ephemeral=True)

class SuggestionModal(discord.ui.Modal):
    def __init__(self):
        super().__init__(title="Anonymous Suggestion")
        self.add_item(discord.ui.InputText(label="What do you want to suggest?", style=discord.InputTextStyle.long))

    async def on_submit(self, interaction: discord.Interaction):
        suggestion = self.children[0].value
        channel = discord.utils.get(interaction.guild.channels, name="suggestions")
        if channel:
            try:
                await channel.send(f"New Anonymous Suggestion:\n{suggestion}")
                await interaction.response.send_message("Your suggestion was submitted successfully!", ephemeral=True)
            except Exception as e:
                print(f"Error sending suggestion: {e}")
                await interaction.response.send_message("Something went wrong while submitting your suggestion.", ephemeral=True)
        else:
            await interaction.response.send_message("The suggestions channel couldn't be found.", ephemeral=True)

@bot.event
async def on_application_command_error(ctx, error):
    print(f"An error occurred: {error}")

bot.run('YOUR_BOT_TOKEN')

The bot functions properly and responds to the $suggestion command, showing the button. However, pressing the button results in an “interaction failed” message with no logs in the console. I’ve tried using different browsers and verified my firewall settings, but I’m still unable to resolve the issue. Any suggestions?

Check your bot permissions in server settings. Had this same problem - my bot could handle regular commands but didn’t have “Use Slash Commands” enabled. Button clicks fail silently when Discord can’t process them without proper permissions. Go to server settings > integrations > your bot and make sure all interaction permissions are checked. Also double-check your bot token hasn’t expired or been regenerated without updating your code.

had the same problem a few weeks back. add timeout=None to your SuggestionView class init method. discord.py views timeout by default and it’ll kill interactions without any error message. also make sure your bot has application commands scope turned on in the oauth2 settings.

Your code looks mostly right, but you’ve got a timing issue. The modal’s probably taking too long to load, or Discord’s 3-second window is timing out. Try deferring the response first - use await interaction.response.defer(ephemeral=True) in your button handler, then await interaction.followup.send_modal(SuggestionModal()). This’ll stop the timeout that’s causing the interaction error. Also check if you’re on a slow connection or VPS - that could be adding delay.