Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py`Discord.Guild.roles`returns`property object at 0x10d57a720`or`';财产';不合适`_Python_Python 3.x_Discord.py - Fatal编程技术网

Python Discord.py`Discord.Guild.roles`returns`property object at 0x10d57a720`or`';财产';不合适`

Python Discord.py`Discord.Guild.roles`returns`property object at 0x10d57a720`or`';财产';不合适`,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,discord.py=版本| 1.6.0:最新版本 Python=版本| 3.9 我整天都在为这件事头疼 出于某种原因,discord.py版本1.6.0discord.Guild.roles中没有返回声明的列表。而是一个不可编辑的属性对象 我尝试过将其解包为循环的元组等,甚至尝试使用fetch\u roles()来绕过这个问题,但这也是不可接受的。在这件事上我只是走到了死胡同 我的目标是迭代这个列表并找到“Basic”。我在公会中的角色。然后使用@client.event装饰程序将其添加到新用

discord.py=版本| 1.6.0:最新版本

Python=版本| 3.9

我整天都在为这件事头疼

出于某种原因,discord.py版本1.6.0
discord.Guild.roles
中没有返回声明的列表。而是一个不可编辑的属性对象

我尝试过将其解包为循环的元组等,甚至尝试使用
fetch\u roles()
来绕过这个问题,但这也是不可接受的。在这件事上我只是走到了死胡同

我的目标是迭代这个列表并找到“Basic”。我在公会中的角色。然后使用
@client.event
装饰程序将其添加到新用户,以检查成员加入时的
。所有这些都可以向该用户发送消息,但我无法让角色返回角色列表

感谢您的帮助

async def on_member_join(member):
    try:
        server = member.guild.name
        user = member.id

        roles_list = discord.Guild.roles
        # Gets the member role as a `role` object

        # should iter over list of roles from above
        role = discord.utils.get(roles_list, name="Basic")

        # Gives the role to the user
        await member.add_roles(role)

        ...

您不应该引用类本身,而是引用实例

roles\u list=server.roles#您在上面定义了它,或者“member.guild.roles”`

discord.py没有这样的版本,最新版本是
1.6.0
,我想你把它和你的pip版本搞混了……啊,好吧,不,你肯定是我看错了版本。这不就是会员的角色吗?我以前是这样设置的,我只得到一个空列表
[]
将通过
discord.utils.get()
运行,因为
'NoneType'对象没有属性“id”
@EdwinCarra否,这是
成员.角色
成员.公会.角色
首先获取成员公会,然后获取该公会中的所有角色。它将为您提供公会的角色,而不是成员的角色,正如stijndcl所说,要获取成员的角色,可以使用
member.roles
遗憾的是,当我运行utils.get时,我得到的非类型对象没有我想要的属性。