【发布时间】:2021-10-11 23:23:38
【问题描述】:
我正在尝试在 Python 中为 Discord 创建一个机器人。但是,我遇到了新添加的按钮的问题。问题如下:我多次使用一个命令,这会导致多个带有按钮的嵌入,但是当我按下其中一个嵌入中的按钮时,也会触发另一个嵌入中具有相同标签的按钮。
我想要的行为是让按钮仅在被点击的嵌入中触发。
我的代码是
async def open(ctx):
def check(res):
return ctx.author == res.user and res.channel == ctx.channel
blue = ["Possibly", "No"]
blueresult = random.choice(blue)
em = discord.Embed(title= f"Congratulations!",description =f"The result is **{blueresult}**!",color = discord.Color.blue())
yes = Button(style=ButtonStyle.green, label="Yes")
no = Button(style=ButtonStyle.red, label="No")
m = await ctx.send(embed = em,components=[[no,yes]])
res = await client.wait_for("button_click", check=check)
user = res.component.label
if player=="Yes":
await m.edit(embed=em,components=[])
elif player=="No":
await m.edit(embed=em,components=[])
【问题讨论】:
标签: python discord discord.py