python - 获取所有成员 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 个服务器上。
谢谢!
解决方案
听起来是个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
推荐阅读
- java - 在初始化之外禁用 JButton
- python - 在 Python 中定义额外变量会导致错误
- android - 应用启动时未调用 FirebaseMessagingService
- javascript - 如何将事件监听器添加到新添加的元素?
- python - 如何使多个目录的 SQLite 数据库目录动态路径?
- javascript - 如何在 Wicket 中重新编码 ajax 行为或阻止请求
- android - 从画廊返回后,不在 Fragment 中调用 onActivityResult
- javascript - 当前时间最接近半小时与下一小时时间
- javascript - 有没有办法访问 ckeditor 元素的原始属性?
- docker - Windows 或非 Linux 操作系统容器如何在 Docker 中工作?