Get Discord user ID from username

Question:

If I have a user’s Discord name and discriminator as a string (e.g ExampleUser#1234) how can I get their user ID from it? I’ve found get_user(id), but that returns a user object from an ID. I’m using Python and Discord.py.

Asked By: clubby789

||

Answers:

As stated in this excellent answer by Sam Rockett (Finding a User ID by Discord Discrim via Python (1st ans) you can try this:

p = client.get_all_members()
found_members = filter(lambda m: m.discriminator==your_discrim, p)
member = discord.utils.get(found_members, name=your_username)
id = member.id

P.S. This snippet 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 already an ID.

Answered By: CFV

In one line just do

discord.utils.get(client.get_all_members(), name="ExampleUser", discriminator="1234").id

notice the .id at the end, that gives you the ID of that person.
Also for the discriminator part don’t include the hash(#)

Answered By: Ecks Dee

I will tell you the best way to do this. You have to search the member user and matching username with member user.

message.guild.members.find(m => m.user.username === 'USERNAME').user.id

https://thediscordbots.blogspot.com/2019/10/what-are-discord-bots-really-and-which.html

Answered By: Joan Cornell
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.