0

Im pretty new to discord.py and would like to get the ids of all the people in the discord server that the bot is used in.

Thanks, Aarav

AaravM4
  • 380
  • 1
  • 4
  • 21
  • Does this answer your question? [How do I make a list of all members in a discord server using discord.py?](https://stackoverflow.com/questions/47733376/how-do-i-make-a-list-of-all-members-in-a-discord-server-using-discord-py) – Patrick Haugh Dec 13 '19 at 01:24
  • No, I am using rewrite which may have some issues. Running the suggested code from the link you posted about says: message object has no attribute server. – AaravM4 Dec 13 '19 at 01:45
  • 2
    Use `guild` instead of `server` – Patrick Haugh Dec 13 '19 at 01:55

1 Answers1

6

First use should get guild object from ctx.guild in command event, message.guild in on_message event, etc. Then choose the sample below.


The sample to go through all members and do some stuff

for member in guild.members:
    id = member.id

    # Do stuff here


The sample to get a list of all members ids

ids = [member.id for member in guild.members]


The sample to get an itterator of all members ids

def get_all_members_ids(guild):
    for member in guild.members:
        yield member.id

# And then use it like this
for id in get_all_members_ids(guild):
    # Do stuff here
Mixno
  • 402
  • 3
  • 10