'Get user's ids to a list from guild discord.py

Is it possible to get all of the members's user ids from a guild (server)?

Edit: I can't use guild, because I need to get the ids when the bot gets online (on_ready)



Solution 1:[1]

You said you wanted to get the member's IDs on_ready in your edit. Down below is a way to get the member ids of everyone from a guild. You alter what you do with member.id if needed I guess.

async def on_ready():
    for guild in bot.guilds():
        for member in guild:
            print (member.id)

As mentioned above by other users, SO is a place to help refractor code or help with errors within pre-existing code, so keep that in mind for next time.

Solution 2:[2]

code snippet from discordpy.readthedocs.io:

async for member in guild.fetch_members(limit=None):
    print(member.id)
# modded a bit to set no limit and attain userid as asked in question

ref: https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild.fetch_members

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Filming
Solution 2 Eric Jin