'discord.py error message: "This interaction failed"

I'm trying to make buttons with discord.py, everything is good and the buttons work well, but even though it gives the error message "This interaction failed"

async def dashboard():
embed=discord.Embed(title="Tile", description="Desc", color=0x00ff00)
embed.add_field(name="Fiel1", value="hi", inline=False)
embed.add_field(name="Field2", value="hi2", inline=False)

channel = bot.get_channel(dashboard_channel_id)
await channel.send(
    embed=embed,
    components=[
    [
    Button(label="عام"),
    Button(label="خاص"),
    Button(label="كتم الصوت"),
    Button(label="فك كتم الصوت"),
    ]])

for the buttons to react I use the on_button_click event

@bot.event
async def on_button_click(interaction):

print("Button clicked")

I tried using on_error event so I can prevent the "This interaction failed" message but that did not work, I just want it not to show this error even if the code is invalid. instead, i want to raise it



Solution 1:[1]

The problem is that discord automatically says "This interaction failed" if the bot doesn't respond to the interaction. So to fix this you just need to respond to the interaction with

await interaction.response.send_message("Button clicked")

you can also defer the interaction if you don't want to send a message:

await interaction.response.defer()

Reference:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chuaat