我有一个问题,我需要从机器人在线的所有服务器中获取所有成员的列表(我正在使用 discord.py 重写),现在我有这个代码片段:
@bot.command()
async def members(ctx):
for guild in bot.guilds:
for member in guild.members:
print(member)
该程序输出机器人名称 3 次,因为机器人在 3 个服务器上。
谢谢!
原文由 Jonathan 发布,翻译遵循 CC BY-SA 4.0 许可协议
听起来像是
Intents
问题。您需要在创建commands.Bot
实例时启用members
意图,并将您的意图传递给它。您还必须在您的开发人员门户中启用它。有关方式和地点的更多信息: https ://discordpy.readthedocs.io/en/latest/intents.html