Skip to content
Advertisement

how to get all members of a guild in discord.py?

So i want to get all members on the discord guild/server printed out in the console but i only get the bot as member. I already activated server member intent on the discord developer portal but it didn’t help. Thanks in advance

here is the code i use:

class MyClient (discord.Client):
    async def on_ready(self):
        guild = client.get_guild(server id)
        print ("ich bin online beep")
        for member in guild.members:
            print (guild.members)

Advertisement

Answer

The reason you are only getting bot, is because you are missing intents. You have to enable intents from the application page for your bot, and also enable intents in your code. Have a look here.

Code should look something like

...
import discord
intents = discord.Intents.default(members=True)
client = commands.Bot(command_prefix = prefix, intents=intents)
...
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement