A
A
Alexander Bondarenko2021-11-17 14:51:12
Python
Alexander Bondarenko, 2021-11-17 14:51:12

How to get all members of a discord.py server?

I'm trying to get all the members of the server in which I myself am, but I only get those with whom there was a correspondence or who are friends, how can I fix this and get everyone?

intents = discord.Intents.all()

client = discord.Client(intents=intents)


async def my_background_task():
    await client.wait_until_ready()
    for guild in client.guilds:
        for ch in guild.text_channels:
            for _ in range(1):
                for member in ch.members:
                    print(member)
                print('-_-')

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')



client.loop.create_task(my_background_task())
client.run("token", bot=False)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HAPPYV0DKA, 2021-11-18
@HAPPYV0DKA

Use the attribute to get server members members. In your case, the cycle through the channels is not needed, the list with server members will be in guild.members. If not all participants turn out this way, then this may be due to the fact that you are using self-bot.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question