Discord.py'不和谐。Guild.roles' 返回 '属性对象在0x10d57a720'或'属性'不可迭代'



discord.py = Version | 1.6.0:latest

Python = Version | 3.9

我一整天都在为这件事绞尽脑汁。

由于某些原因,在discord.py version 1.6.0discord.Guild.roles中没有返回文档中声明的列表。但是一个不可迭代的属性对象

我试过解包,就像它是一个元组a for循环等,甚至试图通过使用fetch_roles()来解决这个问题,但这也是不可迭代的。这件事我一直没有头绪。

我的目标是迭代这个列表并找到"基本"。我在公会里的角色。然后使用@client.event装饰器将其添加到新用户以检查on_member_join。所有这些都可以用于向该用户发送消息,但是我无法让角色返回角色列表。

任何帮助都是感激的。

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_list = server.roles # You defined it above, or `member.guild.roles`

最新更新