If the user reacts with

2019-09-23 17:31发布

Something like this.

@client.event
async def on_reaction_add(reaction, user):
    a = await client.say("React to see help")
    if reaction.emoji == "                

1条回答
来,给爷笑一个
2楼-- · 2019-09-23 18:17

You need to send a message when the bot comes online, then monitor that message for new reactions. The easiest way to do that is with a background loop using Client.wait_for, instead of the on_reaction_add event. The reaction_check function is to make finding the right reactions easier.

from collections.abc import Sequence
from discord import Client

grin = "\N{GRINNING FACE}"

def make_sequence(seq):
    if seq is None:
        return ()
    if isinstance(seq, Sequence) and not isinstance(seq, str):
        return seq
    else:
        return (seq,)

def reaction_check(message=None, emoji=None, author=None, ignore_bot=True):
    message = make_sequence(message)
    message = tuple(m.id for m in message)
    emoji = make_sequence(emoji)
    author = make_sequence(author)
    def check(reaction, user):
        if ignore_bot and user.bot:
            return False
        if message and reaction.message.id not in message:
            return False
        if emoji and reaction.emoji not in emoji:
            return False
        if author and user not in author:
            return False
        return True
    return check

client = Client()

async def background_loop():
    await client.wait_until_ready()
    channel = client.get_channel(int(*SOME CHANNEL ID*))
    msg = await channel.send("React to see help")
    await msg.add_reaction(grin)
    while not client.is_closed:
        res = await client.wait_for('reaction_add', check=reaction_check(message=msg, emoji=grin))
        if res:  # not None
            await msg.edit(content="Moderator commands")

client.loop.create_task(background_loop())
client.run("TOKEN")
查看更多
登录 后发表回答