获取所有成员discord.py

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

@bot.command()
async def members(ctx):
    for guild in bot.guilds:
        for member in guild.members:
            print(member)

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

谢谢!

回答

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

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

client = commands.Bot(intents=intents, prefix_and_other_things_go_here)

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


以上是获取所有成员discord.py的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>