Discord button failure discord.py

Viewed 22

I am getting a failed interaction when anyone presses my discord button, but it is executing all of the code (ie the final message is sent to users). Help please!

###code to add a join button

button = discord.ui.Button(label="Join village", emoji="", style=discord.ButtonStyle.green)
async def button_callback(interaction):
    if interaction.user.id in Rooms[room].players:
        await interaction.user.send("You are already in room %s" % room)
        return
    Rooms[room].add_player(interaction.user.id)
    await interaction.user.send("You have joined room %s" % room)
button.callback = button_callback
view = discord.ui.View()
view.add_item(button)
await ctx.send("Join the new %s village by clicking here! Note: expect an 'This interaction failed'- don't worry "
               "you are still added to the game!" % room, view=view)

Picture of code

Failure of button

1 Answers

You can try interaction.response.send_message() and if you want to make it private add ephemeral=True inside the perameter like interaction.response.send_message("Your message", ephemeral=True)

Related