Why i have the "Interaction Failed" message after clicking on any button on embed :

Viewed 758

I recently tried to create a command with discord_components Buttons to create a channel logs and a welcome channel, the bot asks if there is a channel logs or welcome, and if the user answers "No" then the bot creates a channel logs or welcome. Normally I should get the 'Finish' at the end of the command message but instead I get the Interaction Failed error.

@bot.command(name="configserver")
@has_permissions(administrator=True)
@bot_has_permissions(administrator=True)
async def configserver(ctx):
    def check(res):
        return ctx.author == res.user and res.channel == ctx.channel

    try:
        file = open("file", "x")
    except FileExistsError:
        os.remove("file")
        file = open("file", "a")

    guild: discord.Guild = ctx.guild
    embed_button = await ctx.send(embed=discord.Embed(
        title="Configuration", 
        description="There is a **logs** channel ?", 
        color=get_color(0x3ef76f, 0xe8f73e, 0xf73e3e)), 
        components=[[
            Button(style=ButtonStyle.green, label="Yes"), 
            Button(style=ButtonStyle.red, label="No")
            ]])

    # For channel logs
    res = await bot.wait_for("button_click", check=check)
    
    if res.component.label == "Yes":
        await res.respond(
        content=await embed_button.edit(embed=discord.Embed(
            title="Configuration", 
            description="There is a **welcome** channel ?", 
            color=get_color(0x3ef76f, 0xe8f73e, 0xf73e3e)), 
            components=[[
        Button(style=ButtonStyle.green, label="Yes"), 
        Button(style=ButtonStyle.red, label="No")
        ]])
        )
        res = await bot.wait_for("button_click", check=check)
        await res.respond(
            type=InteractionType.ChannelMessageWithSource,
            content='Finish'
        )
    elif res.component.label == "No":
        permissions_logs = {
        guild.default_role: discord.PermissionOverwrite(read_messages=False),
        }
        channel_logs: discord.TextChannel = await guild.create_text_channel('logs', overwrites=permissions_logs)
        print(channel_logs.id)
        file.write(f"channel_logs = {channel_logs.id}\n")
        await res.respond(
        content=await embed_button.edit(embed=discord.Embed(
            title="Configuration", 
            description="There is a **welcome** channel ?", 
                color=get_color(0x3ef76f, 0xe8f73e, 0xf73e3e)), 
                components=[[
            Button(style=ButtonStyle.green, label="Yes"), 
            Button(style=ButtonStyle.red, label="No")
            ]])
            )

    # For channel logs
    res = await bot.wait_for("button_click", check=check)

    if res.component.label == "Yes":
        print('Yes')
        await res.respond(
            type=InteractionType.ChannelMessageWithSource,
            content='Finish'
        )
        
    elif res.component.label == "No":
        print('No')
        permissions_welcome = {
        guild.default_role: discord.PermissionOverwrite(write_messages=False),
        }
        channel_welcome = await guild.create_text_channel('welcome', overwrites=permissions_welcome)
        print(channel_welcome.id)

        file.write(f"channel_welcome = {channel_welcome.id}\n")

        await res.respond(
            type=InteractionType.ChannelMessageWithSource, 
            content='Finish'
        )
0 Answers
Related