如何打印公会成员列表?

How to print a list of guild members?

代码如下:

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

结果:Discord 机器人

如何让它打印公会中的每个成员,包括 Bot?

(我的版本是3.7.3)

您需要在机器人设置中启用“特权网关意图”:Discord Developer Portal

import discord
from discord.ext import commands

intents=intents=discord.Intents.all()
bot = commands.Bot('!',intents=intents)

@bot.event
async def on_ready():
    print("Bot is Online!")

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

bot.run("TOKEN")