【问题标题】:how to get all members of a guild in discord.py?如何在 discord.py 中获取公会的所有成员?
【发布时间】:2021-03-14 13:21:10
【问题描述】:

所以我想在控制台中打印出不和谐公会/服务器上的所有成员,但我只让机器人成为成员。我已经在不和谐开发者门户上激活了服务器成员意图,但它没有帮助。提前致谢

这是我使用的代码:

class MyClient (discord.Client):
    async def on_ready(self):
        guild = client.get_guild(server id)
        print ("ich bin online beep")
        for member in guild.members:
            print (guild.members)

【问题讨论】:

  • 您确定其他成员在您运行时在线吗?
  • 我运行此程序时其他成员在线,但我也想获得离线成员

标签: python discord discord.py


【解决方案1】:

尝试使用print(member.name) 而不是print(guild.members)

【讨论】:

  • 它的结果相同,我只得到了机器人,除了这一次逻辑上只有名字。
【解决方案2】:

您只获得机器人的原因是因为您缺少意图。您必须从应用程序页面为您的机器人启用意图,并​​在您的代码中启用意图。看看here。

代码应该类似于

...
import discord
intents = discord.Intents.default(members=True)
client = commands.Bot(command_prefix = prefix, intents=intents)
...

【讨论】:

    猜你喜欢
    • 2020-11-11
    • 2021-12-17
    • 2021-08-18
    • 1970-01-01
    • 2021-04-24
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多