如何获得discord公会(discord.py)的成员?

How to get members of a discord guild(discord.py)?

我知道这个问题的一些答案是:

for member in guild.members:
    id = member.id
    #do stuff here

但是不,这对我不起作用,我已经尝试过了,它只有机器人本身在成员列表中,尽管它确实显示了实际的成员数量(但我不确定是否这在任何方面都是有用的)。所以我问是否有另一种方法可以做到这一点。

新的 Discord intents 系统破坏了很多东西,所以你需要确保 discord.py 已更新,并用所有 intents 实例化你的客户端:

intents = discord.Intents.all()
client = discord.Client(intents=intents)