Discord py - 当用户添加反应时给出一个角色

时间:2021-06-09 08:07:56

标签: python discord discord.py bots roles

我想创建一个显示更新的 ChangeLog 房间。 on_message 部分可以正常工作。 Screen of the message displayed in the salon

并且 on_raw_reaction_add 部分不起作用。控制台中没有错误。当点击铃铛表情符号时,用户通常会有一个额外的角色(ChangeLog)Screen Role name

我的代码:

@bot.event
async def on_message(message):
    await bot.process_commands(message)
    if (message.channel.id == 846081235465797662):
        if message.author.bot:
            return
        else:
            await message.delete()
            channel = bot.get_channel(846081235465797662)
            
            desc = await message.channel.send(
                f"**⚙️ CHANGELOG DU {ddmmYY} - <@&851702594837413929>**\n\n" + 
                message.content)
            await desc.add_reaction('?')


@bot.event
async def on_raw_reaction_add(payload):

    emoji = payload.emoji.name
    canal = payload.channel_id
    message = payload.message_id

    role = discord.utils.get(bot.get_guild(payload.guild_id).roles,
           name="ChangeLog")
    membre = bot.get_guild(payload.guild_id).get_member(payload.user_id)


    if canal == 846861087600148540 and emoji == "?":
        await membre.add_roles(role)

1 个答案:

答案 0 :(得分:0)

错误代码:

@bot.event
async def on_raw_reaction_add(payload):

    emoji = payload.emoji.name

    ...

    if canal == 846861087600148540 and emoji == "?":
        await membre.add_roles(role)

payload.emoji.name == "?"?
正确的代码:

@bot.event
async def on_raw_reaction_add(payload):
    emoji = payload.emoji.__str__()
    ...

试试