如何更改Discord.py按钮的颜色并在交互时禁用

huangapple go评论63阅读模式
英文:

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

问题

我试图将按钮颜色更改为灰色,并在单击后禁用它,但似乎没有任何我找到的方法起作用。这似乎应该很简单,我尝试了'edit_message',但也许我用错了。这是我的按钮代码,我删除了所有与此无关的代码。

我真的很感激你能提供的任何帮助。
谢谢!

    @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="让我们开始吧!", 
                                                ephemeral=True)
英文:

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)

答案1

得分: 1

你可以使用disabled属性来禁用按钮,并使用style属性来更改样式。

@discord.ui.button(label="每日游戏", 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="让我们开始吧!", ephemeral=True)
英文:

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)

huangapple
  • 本文由 发表于 2023年2月19日 22:31:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75500838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定