如何使用 discord.py 获取不和谐服务器中所有成员的列表
问题描述
我正在尝试生成我服务器中所有成员的列表:
I am trying to generate a list of all of the members in my server:
@client.event
async def on_ready():
for guild in client.guilds:
for member in guild.members:
print(member)
但是它只打印自己而不打印其他成员.我写错了什么还是我需要对机器人做些什么?
However it is only printing itself and none of the other members. Have I written something wrong or is there something I need to do with the bot?
解决方案
需要开启intents.members
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(..., intents=intents)
# Or if you're using `discord.Client`
client = discord.Client(intents=intents)
还要确保在开发者门户
文档
相关文章