【问题标题】:Check if a specific user reacted discord.py检查特定用户是否对 discord.py 做出反应
【发布时间】:2021-01-06 07:30:38
【问题描述】:

我正在寻找一个脚本来检查执行命令 (ctx.message.author) 的用户是否对带有复选标记的消息做出反应,它应该如下所示:

@client.command()
async def test(ctx):
    message = await ctx.send("Test")
    for emoji in ('✅'):
        await message.add_reaction(emoji) 
        # Here it should detect if the ctx.message.author has reacted

【问题讨论】:

    标签: discord discord.py discord.py-rewrite


    【解决方案1】:

    您可以通过用户 ID 和使用wait_for 进行检查:

    import asyncio # for the exception
    
    @client.command()
    async def test(ctx):
        message = await ctx.send("Test")
        for emoji in ('✅'):
            await message.add_reaction(emoji) 
    
            try:
    
                # the wait_for will only register if the following conditions are met
                def check(rctn, user):
                    return user.id == ctx.author.id and str(rctn) == '✅'
    
                # timeout kwarg is optional
                rctn, user = await client.wait_for("reaction_add", check=check, timeout=30)
    
                # then execute your code here if the author reacts, like so:
                await ctx.send("I detected the author reacting!")
    
            # throws this error if user doesn't react in time
            # you won't need this if you don't provide a timeout kwarg in wait_for()
            except asyncio.TimeoutError:
                await ctx.send("Sorry, you didn't react in time!")
    

    参考资料:

    【讨论】:

      猜你喜欢
      • 2020-11-20
      • 2019-02-03
      • 2020-03-28
      • 1970-01-01
      • 2021-02-22
      • 2019-05-24
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      相关资源
      最近更新 更多