'Discord.py Button Interaction Failed at user click

I'm trying to create a verification function for Discord Bot using buttons. I have tried creating it, but not sure if it works (testing purpose) .

I need it to give a role to verify a user like a role called Verified, would also like a suggestion on how I can make it not a command and just make it a embed in a single channel where new members can just simply click on it and get the role to be verified.

I'm not getting any errors in the console of development, it's just saying when I click the button in the UI (Discord App) I get an message saying "Interaction failed".

@client.command()
async def verify(ctx):
    member = ctx.message.author
    role = get(member.guild.roles, name="Sexy EGirl")
    await ctx.send(
        embed = discord.Embed(description="Click below to verify", color=getcolor(client.user.avatar_url)),
        components = [
            Button(style=ButtonStyle.blue, label = 'Verify')
        ]
        )
    interaction = await client.wait_for("button_click", check=lambda i: i.component.label.startswith("Verify"))
    await interaction.respond(member.add_roles(role))


Solution 1:[1]

You get "Interaction failed", if you don't send a respond message.

@client.event
async def on_button_click(interaction):

    message = interaction.message
    button_id = interaction.component.id
    if button_id == "verify_button":
        member = message.guild.get_member(interaction.user.id)
        role = message.guild.get_role(859852728260231198)  # replace role_id with your roleID
        await member.add_roles(role)

        response = await interaction.respond(embed=discord.Embed(title="Verified"))


@client.command()
@commands.has_permissions(administrator=True) # you need to import command from discord.ext if you want to use this -> from discord.ext import commands
async def verify(ctx):
    await ctx.send(
        embed=discord.Embed(title="Embed - Title", description="Click below to verify"),
        components=[
            Button(style=ButtonStyle.blue, label='Verify', custom_id="verify_button")
        ])

With this code you are able to send an embed with a verify button in a channel. (if you have administrator permissions) Then the user can press on the button and the on_button_click event will be triggered.

To handle the Interaction failed, you are sending a respond message.

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 taktischer