Disable a button after it is clicked on discord.py

Viewed 39

I am trying to disable the "Next" button after it has been clicked once. When a user clicks on "Next", the bot replies to itself with the next page of the weekly tasks.

global WEEK_NUM

next_button = interactions.Button(
    style=interactions.ButtonStyle.PRIMARY,
    label="Next",
    custom_id="next",
    disabled = False
)
async def week_choose(ctx: interactions.CommandContext, week_number: int):

        global WEEK_NUM
        WEEK_NUM = week_number
        embeds = interactions.Embed(
        title=f"Deadlines for Week {week_number}",
        description=Dates[week_number],
        color=0x00ff00
        )
        embeds.add_field(name="Summatives:", value=Summatives[week_number], inline=False)
        if (week_number == 1):
            await ctx.send(embeds = embeds, components = next_button)

        @bot.component("next")
        async def button_response(ctx):
            global WEEK_NUM
            forward = WEEK_NUM
            WEEK_NUM += 1
            forward = forward + 1
            embeds1 = interactions.Embed(
                title=f"Deadlines for Week {forward}",
                description=Dates[forward],
                color=0x00ff00
            )
            embeds1.add_field(name="Summatives:", value=Summatives[forward], inline=False)
            await ctx.send(embeds = embeds1, ephemeral=False)

If I add next_button.disabled = True after await ctx.send(embeds = embeds, components = next_button) it disables the button after it has been called once which seems logical. Is there a way to do this around? I am using interactions.py

1 Answers

You could try this one: I've used this with the discord.py but I am not sure if it's the same as in interactions.py

next_button.disabled = True
await ctx.send(embeds = embeds1, ephermeral=False, components=next_button)
Related