首页 > 解决方案 > 有没有办法用 discord.py 列出不和谐服务器的所有成员

问题描述

我想检索包含不和谐服务器一部分的所有人的列表。

import discord
from discord.ext import commands
TOKEN = 'my_token'
bot = commands.Bot(command_prefix = '!')

@bot.command()
async def members(ctx):
    for member in ctx.guild.members:
        await ctx.send(member)

bot.run(TOKEN)

每当使用 !members 时,我都会得到一个当前在语音频道中或以某种方式在服务器上处于活动状态的所有成员的列表,但我想让那些刚刚显示为在线甚至离线的成员。有人有什么想法吗?

标签: pythondiscorddiscord.py

解决方案


自上次更新以来,您必须启用意图。从开发门户启用它们并自行编写代码。

在此处输入图像描述

intents = discord.Intents().all()
bot = commands.Bot(command_prefix="$", intents=intents)

删除该行server = bot.get_guild(SERVER_ID)


推荐阅读