python - 如何使用 discord.py 列出 discord 服务器中的所有成员?

标签 python server discord discord.py

我正在编写一个 discord 机器人,当我尝试使用命令 !members in on_message 事件从服务器中拉出所有成员时遇到了这个错误:

elif message.content.startswith('!members'):
    x = server.Server.members
    for member in x:
        print(member)

我希望此命令拉取所有成员并在控制台中打印出来,但出现错误

TypeError: 'property' object is not iterable

当我在不和谐 channel 中键入命令时。谁能帮我列出 channel 中所有成员的名单,以便我进一步使用?

最佳答案

您需要一个服务器实例来从中获取成员列表。

假设此代码出现在 on_message(message) 中,您应该能够更改您的

x = server.Server.members

x = message.server.members

请注意,使用带有大写 S 的 Server 将返回类定义,而使用消息中的 server 属性(小写 s)将检索 Server 的实例。

如果您使用的版本 >= 1.0.0,则为

x = message.guild.members

相反。

关于python - 如何使用 discord.py 列出 discord 服务器中的所有成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47733376/

相关文章:

python - MySQLdb 通过代理

http - NGINX try_files 回退

nginx - 使用 nginx 保护 https 以获取私有(private) IP 地址

html - Discord 如何嵌入 YouTube 可播放视频?

javascript - Discord.js 错误 = "message is not defined"

python - 你如何从给定的 scipy 随机分布中抽取随机数?

python - 按月份名称对 pandas 数据框系列进行排序

python - 将 CSV 文件导入 MongoDB 时,文件大小要求是否会发生变化?

Java 服务器具有许多客户端连接而不会出现瓶颈

python - 齿轮已加载,但功能不起作用(discord.py)