我正在尝试使用他们的ID从不和谐的服务器中获取某些用户对象,但是由于某种原因,它无法获取行会对象。我的代码:
@botclient.event
async def on_ready():
for x in all_ids:
guild = botclient.get_guild(GUILD)
user=guild.get_member(x)
all_urls[x]=user.avatar_url
botclient.run(TOKEN)
[上面进一步指定了TOKEN和GUILD,我已经检查了多次,它们似乎没有什么问题]
以前,它在较小的服务器上工作过,我已经尝试了几种变体,但每个变体都给我一个AttributeError:
user=guild.get_member(x)
AttributeError: 'NoneType' object has no attribute 'get_member'
(有时在尝试获取头像URL时也会发生这种情况)
我启用了日志记录功能,并且在发生异常之后,它将输出(我已经删除了行会ID)
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 1000 members in guild ID -.
INFO:discord.state:Processed a chunk for 107 members in guild ID -.
..这使我相信它实际上成功地获得了公会,但是由于某些原因,它在代码中不起作用
如果有人能指出要在哪里找到它/指出我犯的任何错误,我将找不到任何文档,
答案 0 :(得分:0)
您已将漫游器添加到服务器了吗?
经过一些测试,似乎如果没有允许漫游器访问服务器,就无法获取该数据。如果没有,请添加它,然后重试,应该可以。
编辑
@bot.command()
async def getMembers(ctx):
members = ctx.guild.members
print(members[:10])
答案 1 :(得分:0)
我通过使用await client.fetch_member()
而不是guild.get_member()
使它起作用!
尽管如此,仍然不明白为什么guild.get_member()
无法正常工作...
我将来可能会需要它,但是如果那时我仍然无法使它工作,那是很可惜的,但是我想这现在是一个解决方案。