Find all User's UserID in a server

旧城冷巷雨未停 提交于 2019-12-11 17:13:26

问题


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:


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))


来源:https://stackoverflow.com/questions/47732711/find-all-users-userid-in-a-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!