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

Discord.py embed组件中禁用/冻结按钮的实现问题

示例图片

我正在复刻一款Discord机器人,想要实现下述功能:按下embed下方任意按钮后会弹出下拉菜单,此时仅可操作下拉菜单,其余所有按钮都会被冻结禁用。我在谷歌搜索过相关方案但没有找到有效解法。

示例图片

已尝试的代码

Button(
    style=ButtonStyle.gray ,
    label="Add Req.",
    custom_id="add_req",
    emoji='➕'),
Button(
    style=ButtonStyle.gray,
    label="Add Mult.",
    custom_id="add_mult",
    emoji='➕'))

columns_of_buttons = ActionRow(
    Button(
        style = ButtonStyle.gray,
        label= "Remove Item",
        custom_id="remove_item",
        emoji='➖'),
    Button(  
        style = ButtonStyle.gray,
        label= "Start",
        custom_id="start",
        emoji='➡'))

msg = await ctx.send(embed = embed ,components= [row_of_buttons , columns_of_buttons])
on_click = msg.create_click_listener(timeout=60)
@on_click.matching_id("add_req")
async def add_req(ctx):
    embed.clear_fields()
    emb = discord.Embed(title = 'Add new Requirement' , description = '**Choose a requirement type**')
    await msg.edit(embed = emb , components=[])

最终实现方案

我已经通过下述代码成功实现了该功能:

ActionRow.disable_buttons(row_of_buttons)
ActionRow.disable_buttons(columns_of_buttons)

内容的提问来源于stack exchange,提问作者Hiresh Verma

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 06:06:05