Wait_For_Reaction()多个表情符号

问题描述 投票:0回答:1

我正在寻找一个命令,如果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)) 
python python-3.x discord discord.py
1个回答
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))
© www.soinside.com 2019 - 2024. All rights reserved.