英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论