'Discord.py try to get all user list in discord
i try to get all users my discord channel, i send message bot !find but its response how can iget all members id ?
[<Member id=****name='*****' discriminator='6148' bot=True nick=None guild=<Guild id=******name='*******' shard_id=None chunked=False member_count=104>>]
import discord
TOKEN = ""
GUILD = ""
CHANNEL_ID = ""
client = discord.Client()
@client.event
async def on_message(message):
print(message.content)
members = client.guilds[0].members
print(members[:10])
client.run(TOKEN)
Solution 1:[1]
You will need to loop through your list of Members and grab each of their ID. For example:
# ... other code
members = client.guilds[0].members
member_ids = []
for member in members:
member_ids.append(member.id)
print(member_ids)
# ... other code
Or, even better, you can use a list comprehension:
# ... other code
members = client.guilds[0].members
member_ids = [member.id for member in members]
print(member_ids)
# ... other code
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 | Gaberocksall |
