Discord bot不会返回所有成员

时间:2020-11-02 11:46:31

标签: python discord discord.py-rewrite

我制作了一个不和谐的机器人,并想添加!server命令来查看服务器信息。我添加了成员​​部分,但返回1,但是我的服务器有2个人成员和4个机器人(都是我的)为什么?这是代码:

@bot.command()
async def server(ctx):
    membersInServer = ctx.guild.members
    botsInServer = list(filter(filterOnlyBots, membersInServer))
    serv_emb = discord.Embed(title = f'Info about server {ctx.guild.name}')
    serv_emb.add_field(name = 'Members', value = f'All: {len(membersInServer)}\nBots: {len(botsInServer)}')
    await ctx.send(embed = serv_emb)

1 个答案:

答案 0 :(得分:0)

我建议不要依赖较旧版本的discord.py,因为这可能会阻止您将来访问新功能和错误修复。

首先,通过转到https://discord.com/developers/applications/<app_id>/bot并选中“服务器成员身份”,在Discord应用程序上启用成员特权意图。

然后,通过以下方式使用成员意图:

import discord

intents = discord.Intents(members=True)
client = commands.Bot(command_prefix="!", intents=intents)

# The remainder of your code...

您就可以开始了!

相关问题