Mehmet
Mehmet

Reputation: 31

Get All Members from a Guild in Discord.py

Hey this is my following code and it works, but I only get the users with whom I chatted(in private chat) once.


@client.command()
async def hi(ctx):
    with open('users.txt','w') as f:
        for member in ctx.guild.members:
            print("{},{}".format(member,member.id), file=f,)
        print("done")

Upvotes: 3

Views: 13648

Answers (2)

iamthetrueyes
iamthetrueyes

Reputation: 1

Do you have Intents enabled, if not, enable them and try.

Upvotes: 0

Patrick Haugh
Patrick Haugh

Reputation: 60984

You might need to call fetch_members to update the clients internal cache from the Discord API:

@client.command()
async def hi(ctx):
    with open('users.txt','w') as f:
        async for member in ctx.guild.fetch_members(limit=None):
            print("{},{}".format(member,member.id), file=f,)
    print("done")

Upvotes: 4

Related Questions