【问题标题】:How to give role to user for reaction如何为用户赋予角色以进行反应
【发布时间】:2018-07-20 21:40:11
【问题描述】:

如果用户在特殊消息中添加反应: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())

【问题讨论】:

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


    【解决方案1】:

    如果您查看文档,就会发现有一个名为 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-12
      • 2019-09-22
      • 2021-08-26
      • 2021-08-04
      • 1970-01-01
      • 2019-05-31
      • 1970-01-01
      • 2019-10-19
      相关资源
      最近更新 更多