Wait_For_Reaction()多个表情符号

时间:2019-04-18 04:20:49

标签: python python-3.x discord discord.py

我正在寻找一个命令,如果message.author标记了一个用户,则机器人将对该消息作出两次反应,然后等待被标记的用户选择一个或另一个反应。现在,一切正常,除非用户对一个或另一个表情符号做出反应,但它什么也没做。当他们对两个表情符号都做出反应时,它将发送reaction的消息。

if message.content.lower().startswith('!marry'):
    user = message.mentions[0]
    if message.author == user:
        await client.send_message(message.channel, "{} you can't marry yourself dummy ".format(message.author.mention))             
    else:
        if get_spouse(message.author) != "No One":
            await client.send_message(message.channel, "{}, you're already married to {} ".format(message.author.mention, get_spouse(message.author)))
        else:
            if (get_spouse(user)) != "No One":
                await client.send_message(message.channel, "{} is already married. Get your own spouse. ".format(user.mention))
            else:
                marriagemsg = await client.send_message(message.channel, "{} *has proposed to* {} ".format(message.author.mention, user.mention))
                await client.add_reaction(marriagemsg, "✅")
                await client.add_reaction(marriagemsg, "❌")
                while True:
                    reaction = await client.wait_for_reaction(emoji="✅", message=marriagemsg, 
                                        check=lambda reaction, user: user == message.mentions[0])
                    reaction2 = await client.wait_for_reaction(emoji="❌", message=marriagemsg, 
                                        check=lambda reaction, user: user == message.mentions[0])
                    if reaction:
                        await client.send_message(message.channel, "{} **is now married to** {} ".format(message.author.mention, reaction.user.mention))
                        add_spouse(message.author, user.name)
                        add_spouse(reaction.user, message.author.name)
                    else:
                        if reaction2:
                            await client.send_message(message.channel, "{} **rejects** {}**'s proposal** ✋".format(reaction2.user.mention, message.author.mention)) 

1 个答案:

答案 0 :(得分:2)

您正在使用的多个wait_for_reaction检查导致此问题。机器人会一直等到用户对marriagemsg上的react做出反应,然后才检查用户是否对react做出反应。

不要使用多个wait_for_reaction检查,只需使用一个并在列表中填充表情符号即可。您也可以使用elif代替else: if

if message.content.lower().startswith('!marry'):
    user = message.mentions[0]
    if message.author == user:
        await client.send_message(message.channel, "{} you can't marry yourself dummy ".format(message.author.mention))             
    else:
        if get_spouse(message.author) != "No One":
            await client.send_message(message.channel, "{}, you're already married to {} ".format(message.author.mention, get_spouse(message.author)))
        else:
            if (get_spouse(user)) != "No One":
                await client.send_message(message.channel, "{} is already married. Get your own spouse. ".format(user.mention))
            else:
                marriagemsg = await client.send_message(message.channel, "{} *has proposed to* {} ".format(message.author.mention, user.mention))
                await client.add_reaction(marriagemsg, "✅")
                await client.add_reaction(marriagemsg, "❌")
                answer = await client.wait_for_reaction(emoji=["✅", "❌"], message=marriagemsg, 
                                        check=lambda reaction, user: user == message.mentions[0])

                if answer.reaction.emoji == "✅":
                    await client.send_message(message.channel, "{} **is now married to** {} ".format(message.author.mention, answer.user.mention))
                    add_spouse(message.author, user.name)
                    add_spouse(answer.user, message.author.name)
                elif answer.reaction.emoji == "❌":
                    await client.send_message(message.channel, "{} **rejects** {}**'s proposal** ✋".format(answer.user.mention, message.author.mention))