简体   繁体   English

通过Python通过Discord Discrim查找用户

[英]Finding a user by Discord Discrim via Python

Once again, I'm into Discord bot coding. 再一次,我要参与Discord机器人编码。

This time, I'm trying to make a way to find a user by it's Discrim. 这次,我正在尝试找到一种通过Discrim查找用户的方法。 Getting the user by it's Discrim, would easly allow to do another things, like, find his ID, that by the meaning time, the profile picture, name... 通过Discrim吸引用户,很容易允许做其他事情,例如找到他的ID,即通过含义时间,个人资料图片,姓名...

According to discord.py, we need to use get_user_info(user_id). 根据discord.py,我们需要使用get_user_info(user_id)。 But finding someone's ID can be hard for some, so if I could get the ID by the discrim and then do whatever, would be much easier. 但是,对于某些人来说,找到某人的ID可能很困难,因此,如果我可以凭空获取ID然后执行任何操作,将会容易得多。

I tried do the following: 我尝试执行以下操作:

DefaultUser = discord.User
hi = DiscrimIguess[0]
hi2 = discord.User.discriminator.hi

You get the"DiscrimIguess", when the user types the command plus the discrim. 当用户键入命令和识别码时,您将获得“ DiscrimIguess”。

Any way I can do this? 有什么办法可以做到吗? Because it won't work. 因为这行不通。

Firstly, you should not be using a discrim to find a user. 首先, 您不应使用歧视来寻找用户。 IDs are unique, discrims are not. ID是唯一的,区分不是。

Discrims are given to each member to help determine who is who when two members share the same name (ie test#0001 and test#0002 are different people) 对每个成员进行区分以帮助确定两个成员共享相同名称时的身份(例如,test#0001和test#0002是不同的人)

Anyway, while you cannot find a single specific user by discrims, you can find a list of all the users who share a discrim by using Client.get_all_members 无论如何,虽然您无法通过区分找到单个特定用户,但是可以使用Client.get_all_members找到共享区分的所有用户的列表。

p = client.get_all_members()
found_members = filter(lambda m: m.discriminator==DiscrimIguess[0], p)

If you also have a username you can narrow that list down to a single member and then get the ID from that. 如果您还有用户名,则可以将该列表缩小到单个成员,然后从中获取ID。

member = discord.utils.get(found_members, name=username)
id = member.id

This method only works for finding members who share a server with the bot. 此方法仅适用于查找与机器人共享服务器的成员。 To find users who do not share a server with the bot, you must have an ID already for `Client.get_user_info' 要查找不与漫游器共享服务器的用户,您必须已经具有“ Client.get_user_info”的ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM