my button have an Interaction failed error | discord.py

85 Views Asked by At

I created a button on my discord bot using various tutorials, but it still doesn't work. I've tried everything, but it still gives the error Interaction failed

my code:

import discord
from discord.ext import commands
from discord.ui import Button, View

bot = commands.Bot(command_prefix='k.', intents=discord.Intents.all())

@bot.command()
async def meow(ctx):
    await ctx.send('click `meow` button pls', view=View(
        Button(custom_id='click', 
               label='meow!', 
               style=discord.ButtonStyle.blurple)))

    interaction = await bot.wait_for('interaction', 
                                    check=lambda i: i.custom_id == 'click')
    await interaction.response.edit_message(content='meow!', view=None)

interaction failed screenshot

1

There are 1 best solutions below

0
On

Try to create a class for your button. Call it in the class and respond to the interaction directly.

Example code:

class MyView(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=None)

    @discord.ui.button(label="Test",style=discord.ButtonStyle.green, custom_id="my_custom_button")
    async def testbutton(self,interaction:discord.Interaction,button:discord.ui.Button):
        await interaction.response.send_message("Testing...")

@bot.tree.command(name='testbutton')
async def testbutton(interaction:discord.Interaction):
    await interaction.response.send_message(view=MyView())