Home > OS >  Get a user by username?
Get a user by username?

Time:06-14

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?

CodePudding user response:

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)
})
  • Related