Discord on_reaction_add 错误未知角色

我想创建一个机器人,它将通过反应为用户提供角色。该代码似乎有效,但我在控制台中收到错误。但我收到错误。


Ignoring exception in on_reaction_add

Traceback (most recent call last):

  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 312, in _run_event

    await coro(*args, **kwargs)

  File "slh.py", line 47, in on_reaction_add

    await user.add_roles(user, newrole)

  File "/home/pi/.local/lib/python3.7/site-packages/discord/member.py", line 641, in add_roles

    await req(guild_id, user_id, role.id, reason=reason)

  File "/home/pi/.local/lib/python3.7/site-packages/discord/http.py", line 223, in request

    raise NotFound(r, data)

discord.errors.NotFound: 404 Not Found (error code: 10011): Unknown Role

Ignoring exception in on_reaction_add

Traceback (most recent call last):

  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 312, in _run_event

    await coro(*args, **kwargs)

  File "slh.py", line 47, in on_reaction_add

    await user.add_roles(user, newrole)

  File "/home/pi/.local/lib/python3.7/site-packages/discord/member.py", line 641, in add_roles

    await req(guild_id, user_id, role.id, reason=reason)

  File "/home/pi/.local/lib/python3.7/site-packages/discord/http.py", line 223, in request

    raise NotFound(r, data)

discord.errors.NotFound: 404 Not Found (error code: 10011): Unknown Role

我不知道为什么会出现这个错误。因为“testrole”这个角色存在于我的不和谐中。我尝试将discord.utils.get 与 name="channelname" 和 id="723xxxxx" 一起使用。两者都会带来相同的错误。


机器人拥有不和谐的所有特权/权利。谁能帮我解决这个问题?


这是代码:


@bot.event

async def on_reaction_add(reaction, user):

    if reaction.emoji == '✅':

      newrole = discord.utils.get(user.guild.roles, name="testrole")

      await user.add_roles(user, newrole)

希望有人可以帮助我。


慕码人8056858
浏览 84回答 1
1回答

炎炎设计

问题是它试图添加user为角色。您可以简单地删除它,不需要将其作为参数传递,因为您已经从类中调用该函数。使用这个代替:await user.add_roles(newrole)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python