通过Python通过Discord Discrim查找用户 [英] Finding a user by Discord Discrim via Python

查看:151
本文介绍了通过Python通过Discord Discrim查找用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再一次,我将使用Discord机器人编码。

Once again, I'm into Discord bot coding.

这一次,我正在尝试寻找一种通过Discrim查找用户的方法。
吸引用户使用Discrim,可以轻松地做其他事情,例如找到他的ID,即通过时间,个人资料图片,姓名...的含义。

This time, I'm trying to make a way to find a user by it's 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...

根据discord.py,我们需要使用get_user_info(user_id)。
但是,对于某些人来说,找到某人的ID可能很困难,因此,如果我能凭空获取ID然后执行任何操作,会容易得多。

According to discord.py, we need to use 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.

我尝试执行以下操作:

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

当用户键入命令加号时,将得到 DiscrimIguess

You get the"DiscrimIguess", when the user types the command plus the discrim.

有什么办法可以做到?因为它行不通。

Any way I can do this? Because it won't work.

推荐答案

首先,您不应该使用辨别力来找到用户。 ID是唯一的,区别不是。

Firstly, you should not be using a discrim to find a user. IDs are unique, discrims are not.

当每个成员具有相同的名称(例如,test#0001和test#0002是不同的人)时,会向每个成员提供区分以帮助确定谁是谁。

Discrims are given to each member to help determine who is who when two members share the same name (i.e. test#0001 and test#0002 are different people)

尽管如此,虽然您无法通过区分找到单个特定用户,但是可以使用 Client.get_all_members

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

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

如果您还有用户名,则可以将该列表缩小为单个成员,然后获取ID

If you also have a username you can narrow that list down to a single member and then get the ID from that.

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

此方法仅适用于查找与机器人共享服务器的成员。要查找不与漫游器共享服务器的用户,您必须已经具有`Client.get_user_info'

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'

这篇关于通过Python通过Discord Discrim查找用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆