Search code examples
pythondiscorddiscord.py

How to change Discord.py button color and disable on interaction


I am trying to change the button color to grey and disable it once it is clicked but nothing I find seems to be working. It really seems like it should be simple enough to do and I tried 'edit_message' but maybe I used it wrong. Here is the code for my button, I took out all the irrelevant code.

I really appreciate any help you can offer. Thanks!

    @discord.ui.button(label="Daily Game", style=discord.ButtonStyle.blurple)
    async def daily_fantasy(self, interaction:discord.Interaction, 
                            button:discord.ui.Button):

        await interaction.response.send_message(content=f"Let's get started!", 
                                                ephemeral=True)

Solution

  • You can disable the button using the disabled property. And changing the style using the style property.

    @discord.ui.button(label="Daily Game", style=discord.ButtonStyle.blurple)
    async def daily_fantasy(self, interaction: discord.Interaction, button: discord.ui.Button):
        button.disabled = True
        button.style = discord.ButtonStyle.grey
        await interaction.response.edit_message(view=self)
        await interaction.followup.send(content=f"Let's get started!", ephemeral=True)