snvmk
snvmk

Reputation: 52

Discord bot dont return all members

i making a discord bot, and wanna add !server command to view server info. i add members section, but it returns 1, but my server have 2 human member and 4 bots(all my) Why? 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)

Upvotes: 0

Views: 91

Answers (1)

Thomas Kowalski
Thomas Kowalski

Reputation: 2184

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.

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".

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!

Upvotes: 1

Related Questions