【问题标题】:How to print a list of guild members?如何打印公会成员列表?
【发布时间】:2021-05-01 15:25:03
【问题描述】:
代码如下:
@bot.command()
async def test(ctx):
for member in ctx.message.guild.members:
print(member.name)
结果:Discord Bot
如何让它打印公会中的每个成员,包括机器人?
(我的版本是3.7.3)
【问题讨论】:
标签:
discord.py
python-3.7
【解决方案1】:
您需要在 bot 设置中启用“Privileged Gateway Intents”: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")