discord.py-与多个按钮的互动
我为我的Discord Bot创建了一个带有按钮的命令。 在下面的当前代码中,与蓝色按钮(Button1)的相互作用正常。绿色按钮的交互(Button3)不起作用。
如何为同一命令中的不同按钮创建不同的交互?
我正在使用discord.py和discord_components
@bot.command()
async def test(ctx):
await ctx.send(
"This is a button test.",
components=[
[
Button(
style=ButtonStyle.blue,
custom_id="button1",
label="Blue button",
emoji="
I've created a command with buttons for my Discord bot.
With the current code below, the interaction with the blue button (button1) works fine. Interaction for the green button (button3) does not work.
How do I create different interactions for different buttons within the same command?
I am using discord.py and discord_components
@bot.command()
async def test(ctx):
await ctx.send(
"This is a button test.",
components=[
[
Button(
style=ButtonStyle.blue,
custom_id="button1",
label="Blue button",
emoji="????",
),
Button(
style=ButtonStyle.red,
custom_id="button2",
label="Red button",
disabled=True,
emoji="????",
),
Button(
style=ButtonStyle.green,
custom_id="button3",
label="Green button",
emoji="????",
),
]
]
)
blue = await bot.wait_for(
"button_click", check = lambda i: i.custom_id == "button1"
)
await blue.send(content="Button clicked!", ephemeral=False)
green = await bot.wait_for(
"button_click", check = lambda k: k.custom_id == "button3"
)
await green.send(content="Button smashed!", ephemeral=False)
The bot is currently waiting for the blue button to be pressed. Then the green button works. Obviously I want them to work at the same time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地检查按钮自定义ID是否为
button1
(蓝色)或button3
(绿色)如果您希望按钮不断工作,请将代码放在一段时间内环形
You can simply check if the buttons custom id is either
button1
(blue) orbutton3
(green)If you want the buttons to constantly work, put the code above into a while loop