【发布时间】:2021-07-12 08:37:34
【问题描述】:
所以我最近在我的机器人中遇到了这个我以前没有遇到过的问题......
错误-
Traceback (most recent call last):
File "/home/container/.local/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "/home/container/cogs/mod.py", line 100, in on_raw_reaction_add
await payload.member.add_roles(role, reason="Reaction Roles", atomic=True)
File "/home/container/.local/lib/python3.9/site-packages/discord/member.py", line 764, in add_roles
await req(guild_id, user_id, role.id, reason=reason)
AttributeError: 'NoneType' object has no attribute 'id'
我的代码是:
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
if payload.member.bot:
pass
else:
with open('reactrole.json') as react_file:
data = json.load(react_file)
for x in data:
if x['emoji'] == payload.emoji.name:
role = discord.utils.get(self.client.get_guild(
payload.guild_id).roles, id=x['role_id'])
await payload.member.add_roles(role)
@commands.Cog.listener()
async def on_raw_reaction_remove(self, payload):
with open('reactrole.json') as react_file:
data = json.load(react_file)
for x in data:
if x['emoji'] == payload.emoji.name:
role = discord.utils.get(self.client.get_guild(
payload.guild_id).roles, id=x['role_id'])
await self.client.get_guild(payload.guild_id).get_member(payload.user_id).remove_roles(role)
我刚刚检查了文档并添加了这些额外的参数,例如 reason 和 atomic。
如果您知道此问题的解决方案,请回答。 提前致谢。
【问题讨论】:
标签: python-3.x discord.py attributeerror