我想创建一个机器人,它将通过反应为用户提供角色。该代码似乎有效,但我在控制台中收到错误。但我收到错误。Ignoring exception in on_reaction_addTraceback (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 RoleIgnoring exception in on_reaction_addTraceback (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.eventasync def on_reaction_add(reaction, user): if reaction.emoji == '✅': newrole = discord.utils.get(user.guild.roles, name="testrole") await user.add_roles(user, newrole)希望有人可以帮助我。
1 回答
炎炎设计
TA贡献1808条经验 获得超4个赞
问题是它试图添加user
为角色。您可以简单地删除它,不需要将其作为参数传递,因为您已经从类中调用该函数。使用这个代替:
await user.add_roles(newrole)
添加回答
举报
0/150
提交
取消