如何给用户起反应作用

时间:2018-02-10 04:46:50

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

如果用户在特殊消息中添加反应:HotS_Tank:,机器人将需要将此角色提供给用户,但我不知道该怎么做...

这就是我的尝试:

async def role_background_task():
    await client.wait_until_ready()
    roleChannel = discord.Object(id='411270826374070293')
    roleMSG1 = client.get_message(roleChannel, id='411657109860515840')
    roleMSG2 = client.get_message(roleChannel, id='411657144488689674')
        while not client.is_closed:
            reac1 = await client.wait_for_reaction(emoji=':HotS_Tank:411445724287598592',message=roleMSG1)
    if reac1.reaction.emoji == ':HotS_Tank:411445724287598592':
        await client.add_roles(reac1.user, roleHOTS_Tank)
client.loop.create_task(role_background_task())

1 个答案:

答案 0 :(得分:3)

如果您查看文档,则会发生名为on_reaction_add here的事件。你可以简单地使用它。

@client.event
async def on_reaction_add(reaction, user):
    roleChannelId = '411270826374070293'

    if reaction.message.channel.id != roleChannelId:
        return #So it only happens in the specified channel
    if str(reaction.emoji) == "<:HotS_Tank:411445724287598592>":
        await client.add_roles(user, roleHOTS_Tank)