Find all User's UserID in a server

2019-08-22 02:54发布

How would I find and store all of the users UserID's in a discord server?

@client.event
async def on_message(message):
if message.content.startswith("##kickrandom"):
    await client.send_message(message.channel, "Kicking a random user in 30 seconds...")

1条回答
不美不萌又怎样
2楼-- · 2019-08-22 03:33

Each user only has 1 ID, so you can get a full list of members on the server and grab the ID of each

ids = []
for m in server.members:
    ids.append(m.id)

Python has a tool to do this quickly called list compression.

ids = [m.id for m in server.members]

However, if you just want to kick a random member, you can just use

target = random.choice(list(server.members))
查看更多
登录 后发表回答