如何在discord.py中获取所有成员列表?

时间:2020-12-25 14:35:53

标签: python python-3.x discord.py

@client.command() 
async def members_info(ctx):    
    server_members = ctx.guild.members 
    data = "\n".join([member.name for member in server_members if "test" in member.roles])
    embed = discord.Embed(title = f'Участники сервера', description = f"{data}", color = discord.Color.purple())

只输出带有标题和颜色的空嵌入消息,没有描述 我不知道我应该做什么-_-

1 个答案:

答案 0 :(得分:1)

您可能错过了 members 意图。这意味着除非您执行直接 HTTP 请求,否则不会将成员加载到缓存中。启用:

首先在 dev portal 上启用: members intent

第二次订阅discord.py:

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(intents=intents, ...)