【发布时间】:2021-02-08 03:18:36
【问题描述】:
我一直在尝试使用 python 制作一个机器人来实现不和谐。该机器人将成员添加到另一个房间,具体取决于他/她所在的房间。当我尝试运行代码时,我不断收到此错误
AttributeError: 'NoneType' object has no attribute 'roles'
这是我得到错误的定义
def get_sibling_role(member):
roles = member.roles; ret = None #<==there is an issue on this
for role in roles:
if role.name == "Brothers Waiting Room":
ret = ("Brother", role); break
elif role.name == "Sisters Waiting Room":
ret = ("Sister", role); break
return ret
#我已经定义了返回成员ID的成员
谁能帮我找出我定义中的问题?
【问题讨论】:
-
显然
member是None。调用此函数时仔细检查您的数据。 -
你是对的,
member是None。当我尝试单独打印时,它打印了None。我现在正试图看看如何避免让它变空,看看那部分有什么问题。感谢您的帮助。
标签: discord bots python-3.6 typeerror discord.py