如何将角色分配给用户进行反应

2024-10-02 08:22:51 发布

您现在位置:Python中文网/ 问答频道 /正文

如果用户在一条特殊的消息中添加反应:HotS_Tank:,bot将需要将此角色授予用户,但我不知道如何做。。。在

这就是我所尝试的:

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())

Tags: 用户clientidmessagetaskgetawaitrole
1条回答
网友
1楼 · 发布于 2024-10-02 08:22:51

如果您查看文档,会发现一个名为on_reaction_addhere的事件。你可以简单地使用它。在

@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)

相关问题 更多 >

    热门问题