简体   繁体   English

discord bot 用户反应

[英]discord bot user reaction

So I am trying to make my personal "splashbot" for my discord server.所以我正在尝试为我的 discord 服务器制作我的个人“splashbot”。 This is one of the commands that it should do.这是它应该执行的命令之一。 The problem is that I don't know how to check if the player choose one of the reactions.问题是我不知道如何检查玩家是否选择了其中一种反应。 I tried some things out and here is the code:我尝试了一些东西,这里是代码:

@client.command(aliases=['paidsplash'])
async def splash(ctx):
    message = await ctx.send('Are you sure you want to do a paid splash?')
    emoji1 = '✅'
    await message.add_reaction(emoji1)
    emoji2 = '❌'
    await message.add_reaction(emoji2)
    await ctx.message.delete()
    client.wait_for("reaction.users()=='✅'",  timeout=10.0) #reaction.users()?
    await ctx.send('yes')

Basically the player types '*splash', the bots removes that and asks the question + adds those 2 reactions on it.基本上玩家键入“*splash”,机器人将其删除并提出问题+在其上添加这两个反应。 Then the player must pick a reaction.然后玩家必须选择一个反应。 They will be added to a queue if ✅ but I haven't come to that part... Preferable just copy and edit to code in your answer, so I can see what is wrong, I learn the fastest that way如果✅,它们将被添加到队列中,但我还没有进入那部分...最好只是复制并编辑您的答案中的代码,这样我就可以看到哪里出了问题,这样我学得最快

The client.wait_for code is incorrect. client.wait_for代码不正确。 You're supposed to define a check function first, then pass that through to the wait_for function so that it can check for a reaction.您应该首先定义一个检查 function,然后将其传递给wait_for function 以便它可以检查反应。

This is some sample code from the discord.py documentation ( https://discordpy.readthedocs.io/en/latest/api.html#discord.Client.wait_for ) edited to work for your situation.这是 discord.py 文档( https://discordpy.readthedocs.io/en/latest/api.html#discord.Client.wait_for )中的一些示例代码,适用于您的情况。 Essentially, it's just the same thing as the example code but waits for a reaction not done by the bot (or the author of the message in the code)本质上,它与示例代码相同,但等待机器人(或代码中消息的作者)未完成的反应

        def check(reaction, user):
            return user != message.author and str(reaction.emoji) == '👍'

        try:
            reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
        except asyncio.TimeoutError:
            await channel.send('👎')
        else:
            await channel.send('👍')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM