简体   繁体   English

Discord bot 不返回所有成员

[英]Discord bot dont return all members

i making a discord bot, and wanna add !server command to view server info.我正在制作一个不和谐的机器人,并想添加!server命令来查看服务器信息。 i add members section, but it returns 1, but my server have 2 human member and 4 bots(all my) Why?我添加了成员​​部分,但它返回 1,但我的服务器有 2 个人类成员和 4 个机器人(都是我的)为什么? This is code:这是代码:

@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)

I recommend not relying on an older version of discord.py , as that will probably prevent you from accessing new features and bug fixes in the future.我建议不要依赖旧版本的discord.py ,因为这可能会阻止您将来访问新功能和错误修复。

First, enable the Members privileged intent on your Discord application by going to https://discord.com/developers/applications/<app_id>/bot and checking "SERVER MEMBERS INTENT".首先,通过转到https://discord.com/developers/applications/<app_id>/bot并选中“SERVER MEMBERS INTENT”,在您的 Discord 应用程序上启用会员特权意图。

Then, use the Members intents in the following way:然后,按以下方式使用成员意图:

import discord

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

# The remainder of your code...

And you're ready to get going!你已经准备好开始了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM