Discord_Components 允许多个按钮响应

Discord_Components allow multiple button responses

我在使用按钮功能时遇到 Discord 组件问题。

按钮按我的意愿出现,但是如果我 post 有多个问题,一个按钮只有一个用户得到一颗糖果。其他人收到 'this response has already been provided' 或类似的消息。

有没有办法让我多次询问同一个问题并得到每个用户的回复?同一个用户没关系,我只想3个问题3个回复

例如,我要赠送 3 颗糖果。前 3 名点击他们想要的糖果的用户将获得他们选择的糖果。然而,一旦一个用户点击了他们的糖果,其他消息似乎就不再需要响应了。

非常感谢任何帮助。下面的代码。它由我的 discord 中的 !givecandy 命令调用。

embed = discord.Embed(title="Would you like some candy?", colour=discord.Colour(0xffff00),
                                  description="Only one user may claim this candy!\n\nWhat kind of candy would you like?")
            botQuestion = await ctx.channel.send(
                embed=embed,
                components=[
                    [
                        Button(style=ButtonStyle.green, label="Laffy Taffy"),
                        Button(style=ButtonStyle.green, label="Lollipop"),
                        Button(style=ButtonStyle.green, label="Bubblegum"),
                        Button(style=ButtonStyle.green, label="Other")
                    ],
                ],
            )

            def check(res):
                return ctx.author == res.user and res.channel == ctx.channel

            try:
                res = await bot.wait_for("button_click", check=check)
            except:
                await ctx.channel.send("Something went wrong, cancelling...", delete_after=10)
                await botQuestion.delete()
                return

            if res.component.label == "Other":
                await botQuestion.delete()
                embed = discord.Embed("Would you like some candy?", colour=discord.Colour(0xffff00),
                                  description="Only one user may claim this candy!\n\nWhat kind of candy would you like?")
                botQuestion = await ctx.channel.send(
                    embed=embed,
                    components=[
                        [
                            Button(style=ButtonStyle.green, label="Twizzlers"),
                            Button(style=ButtonStyle.green, label="Sour Patch Kids"),
                            Button(style=ButtonStyle.green, label="M & M's"),
                            Button(style=ButtonStyle.green, label="Apple Slices")
                        ],
                    ],
                )

                try:
                    res = await bot.wait_for("button_click", check=check)
                except:
                    await ctx.channel.send("Something went wrong, cancelling...", delete_after=10)
                    await botQuestion.delete()
                    return

        candyRequested = res.component.label
        await asyncio.sleep(1)
        await botQuestion.delete()

知道了,所以我还缺少检查响应的消息 ID。

现在可以正常使用了。

正在使用... messageID = ctx.channel.last_message_id

并包括... res.message.id == messageID

进入我的支票,开始工作了。