Discord 属性错误:';非类型';对象没有属性';角色';

Discord 属性错误:';非类型';对象没有属性';角色';,discord,bots,python-3.6,typeerror,discord.py,Discord,Bots,Python 3.6,Typeerror,Discord.py,我一直在尝试使用python制作一个机器人来处理discord。此bot会根据成员所在的房间将其添加到另一个房间。当我试着运行代码时,我总是遇到这个错误 AttributeError: 'NoneType' object has no attribute 'roles' 这是我得到错误的定义 def get_sibling_role(member): roles = member.roles; ret = None #<==there is an issue on this for ro

我一直在尝试使用python制作一个机器人来处理discord。此bot会根据成员所在的房间将其添加到另一个房间。当我试着运行代码时,我总是遇到这个错误

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
def get_sibling_角色(成员):

角色=成员。角色;ret=None#显而易见的原因是成员的值为None。为了避免出现这种情况,您可以添加“notnone”复选框。我还假设不对齐是因为发布了有问题的代码,而不是在代码中

def get_sibling_role(member):
  if member is None:
    return None

  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
def get_sibling_角色(成员):
如果成员为无:
一无所获

角色=成员。角色;ret=None#非类型问题是一个错误,许多程序员由于几个主要原因而面临discord.py

1-我自己在上一个问题中的错误超出了给定的代码范围。我编写的代码是正确的,但是,我在同一代码中定义了两个客户端实例,这使整个程序变得混乱,对于成员和角色都没有返回任何实例,因此请修改discord.client或commands.Bot构造函数

client=discord.client(意图=意图)
如果您想要测试和调试,我建议您使用on_ready()上的
下的以下代码打印服务器中的第一个成员:
函数

打印(公会成员[1])

2-第二个常见的错误是人们倾向于不使用意图,他们必须使用意图来获得成员 此外,您还应启用它们(特权网关),如discord portal中的上一篇文档所述


3-将discord.py更新为1.5.0版。或更高。确保将其安装到正确的环境中



显然
成员
。调用此函数时,请仔细检查您的数据。您是对的,
成员
None
。当我试图单独打印时,它打印了
None
。我现在试着看看如何避免它变空,看看这部分出了什么问题。谢谢你的帮助。没错,它是空的。现在我将看看如何避免将成员变为空。非常感谢。