Discord Python重写-wait_for('reaction_add')

时间:2020-09-15 05:22:03

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

所以,我试图通过这段代码做出反应

@client.command()
async def test(ctx):
    msg = await ctx.send("Eh idk just react")

    await msg.add_reaction("⬅️")
    await msg.add_reaction("➡️")

    def check(reaction, user):
        return user == ctx.message.author and str(reaction.emoji) in ['⬅️', '➡️']

    try:
        reaction, user = await client.wait_for('reaction_add', timeout=5, check=check)
    
        if reaction == '➡️':
            await ctx.send("NEEXT!")
            return

        elif reaction == '⬅️':
            await ctx.send("RETUUURN!")
            return

    except asyncio.TimeoutError:
        await ctx.send("Timed out")

但是当添加反应时,它什么也没做。有人能帮我吗?我需要1周的反应帮助。

1 个答案:

答案 0 :(得分:2)

与Unicode表情符号进行比较时,您需要使用reaction.emoji

@client.command()
async def test(ctx):
    msg = await ctx.send("Eh idk just react")

    await msg.add_reaction("⬅️")
    await msg.add_reaction("➡️")

    def check(reaction, user):
        return user == ctx.message.author and str(reaction.emoji) in ['⬅️', '➡️']

    try:
        reaction, user = await client.wait_for('reaction_add', timeout=5, check=check)
    
        if reaction.emoji == '➡️':
            await ctx.send("NEEXT!")
            return

        elif reaction.emoji == '⬅️':
            await ctx.send("RETUUURN!")
            return

    except asyncio.TimeoutError:
        await ctx.send("Timed out")