获取所有成员discord.py

Jon*_*han 5 python python-3.x discord.py discord.py-rewrite

我有一个问题,我需要从机器人在线的所有服务器中获取所有成员的列表(我正在使用 discord.py 重写),现在我截断了以下代码:

@bot.command()
async def members(ctx):
    for guild in bot.guilds:
        for member in guild.members:
            print(member)
Run Code Online (Sandbox Code Playgroud)

该程序输出 Bot 名称 3 次,因为该机器人位于 3 个服务器上。

谢谢!

sti*_*dcl 5

听起来是个Intents问题。您需要members在创建commands.Bot实例时启用Intent ,并将您的Intent传递给它。

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(intents=intents, prefix_and_other_things_go_here)
Run Code Online (Sandbox Code Playgroud)

您还必须在开发人员门户中启用它。有关方式和地点的更多信息:https : //discordpy.readthedocs.io/en/latest/intents.html