在服务器中查找所有用户的UserID [英] Find all User's UserID in a server
本文介绍了在服务器中查找所有用户的UserID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在不和谐的服务器中查找并存储所有用户UserID?
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个ID,因此您可以获取服务器上成员的完整列表并获取每个成员的ID。
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有一个工具迅速将其称为列表压缩。
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))
这篇关于在服务器中查找所有用户的UserID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文