Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

discord.py: guild.members returns only bot but no members [duplicate]

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
like image 279
Anthony Hervy Avatar asked Sep 01 '25 20:09

Anthony Hervy


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

like image 75
theX Avatar answered Sep 05 '25 22:09

theX


https://discordpy.readthedocs.io/en/latest/intents.html

Or simply, install version 1.4.2 of the library: pip install -U discord.py==1.4.2

like image 28
akiva Avatar answered Sep 05 '25 22:09

akiva