首页 > 解决方案 > 获取所有成员 discord.py

问题描述

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

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

该程序输出 Bots 名称 3 次,因为 bot 在 3 个服务器上。

谢谢!

标签: pythonpython-3.xdiscord.pydiscord.py-rewrite

解决方案


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

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


推荐阅读