【问题标题】:Discord py detect reactionsDiscord py 检测反应
【发布时间】:2021-11-22 17:35:57
【问题描述】:

我只是想学习如何“阅读”同一机器人发送的消息的反应。我已经被困了好几天了。我查了一下,但我发现的唯一教程是针对角色的特定信息。我不在乎,我不会为整个服务器使用一条消息,所以我无法获取消息的 ID。我只希望机器人发送一条消息,然后用户做出反应,机器人写下“你对 [emoji] 做出了反应”。

我在这个网站上发现了一些问题,但它们只会让我更加困惑。不过,这还是我勉强做到的。

@bot.command()
async def react(ctx):
    await ctx.send("React to me!")

@bot.event
async def on_reaction_add(reaction, user):
            await channel.send("{}, you responded with {}".format(user, reaction))

【问题讨论】:

  • 你知道如何wait_for 一个反应吗?

标签: python discord discord.py bots


【解决方案1】:

在文档中实际上已经有一个很好的例子,你可以在这里找到它:

但是为了简化整个事情,这里有一个示例代码

@bot.command()
async def react(ctx):
    def check(reaction, user):  # Our check for the reaction
        return user == ctx.message.author  # We check that only the authors reaction counts

    await ctx.send("Please react to the message!")  # Message to react to

    reaction = await bot.wait_for("reaction_add", check=check)  # Wait for a reaction
    await ctx.send(f"You reacted with: {reaction[0]}")  # With [0] we only display the emoji

如下所示:

没有reaction[0],你只会得到不必要的信息。 [0] 只显示第一个数字,在本例中为 Reaction emoji

【讨论】:

    猜你喜欢
    • 2021-04-23
    • 1970-01-01
    • 2021-03-02
    • 2022-01-03
    • 1970-01-01
    • 2020-06-27
    • 2021-08-26
    • 2021-03-24
    • 1970-01-01
    相关资源
    最近更新 更多