Discord.py on_raw_reaction_add()缺少1个必需的位置参数:“用户”

时间:2020-08-24 21:52:24

标签: python discord.py

我想让我的机器人在某人对某条消息做出反应时赋予某人特定角色

代码:

@client.event
async def on_raw_reaction_add(reaction, user):
    if reaction.message.id == 747566918466273300 and reaction.emoji in "✅":
        role = discord.utils.get(user.server.roles, name="Member")
        await bot.add_roles(user, role)

我收到错误消息:

Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
  File "C:\Users\Bruker\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 312, in _run_event
    await coro(*args, **kwargs)
TypeError: on_raw_reaction_add() missing 1 required positional argument: 'user'

谢谢

1 个答案:

答案 0 :(得分:2)

由于on_reaction_add事件没有使用userreaction参数,所以您会遇到此异常,例如,您必须使用payload

@client.event
async def on_raw_reaction_add(payload):
    # Code here

然后查看其余代码:

if payload.message.id == 747566918466273300 and payload.emoji.name == "✅":
    role = discord.utils.get(payload.guild.roles, name="Member")
        await payload.author.add_roles(role)