discord.py: guild.members returns only bot but no members

Viewed 5189

I'm trying to make a Discord bot with Python.

In the Discord Developers interface, on my bot panel, "Privileged Gateway Intents" (SERVER MEMBERS INTENT) is checked.

The bot is on a server (guild) with admin authorizations.
I don't understand why the bot returns only itself, but not me or my friend.

for guild in self.discord_client.guilds:
            print(f"guild found : {guild}")
            print(guild.members)
        for member in guild.members:
            print(member)

The code above returns this:

guild found : Testdev   
[<Member id=76277237853886878X name='Dev_Bot' discriminator='6271' bot=True nick=None guild=<Guild id=76114559936167936X name='Testdev' shard_id=None chunked=False member_count=3>>]

member count=3, but after this:

for member in list(guild.members):
    print(member)

it returns only the bot's ID:

Dev_Bot#6271
2 Answers

The only useful answer I have found is here:

Discord Bot can only see itself and no other users in guild

Basically, it says that you have to set the intents to be able to see the guild's members.

So, instead of just client = discord.Client(), you'll have to do:

...

intents = discord.Intents.all()
client = discord.Client(intents=intents)

...

or

intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)

if you want to just have that intent

Related