You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Discord.py中点击按钮后修改颜色为灰色并禁用按钮

解决Discord按钮点击后禁用并变灰的问题

你不需要用edit_message,直接修改按钮实例的属性就能实现效果,步骤如下:

  • 将按钮的disabled属性设为True,禁用按钮
  • 将按钮的style改为discord.ButtonStyle.grey(灰色样式)
  • 调用interaction.message.edit()方法更新消息组件,让修改生效

修改后的代码示例:

@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)
    
    # 修改按钮属性
    button.disabled = True
    button.style = discord.ButtonStyle.grey
    
    # 更新消息组件,使修改生效
    await interaction.message.edit(view=self)

注:如果是在discord.ui.View类中使用该按钮,self就是当前的View实例,直接传入edit()方法即可。

内容的提问来源于stack exchange,提问作者Ryan Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 10:20:22