Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get a user by username?

I would like to get a user by the username. I know how that works:

let user = client.users.find(user => user.username == "TESTname");

But what if there are 2 users who have the same username?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

although getting a user with username instead of with id is a terrible idea, here is how you can do it with V13 :

const users = client.users.cache.filter(user => user.username == "TESTname");

consider it is preferable to have the ID of the user, so you can fetch it directly from Discord:

client.users.fetch("304541381798658048").then(user => {
console.log(user)
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading