0

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?

  • If there are multiple matches and you want them all, then use `.filter` instead of `.find` – Nicholas Tower Jun 14 '22 at 12:32
  • Does this answer your question? [Find all objects with matching Ids javascript](https://stackoverflow.com/questions/37863855/find-all-objects-with-matching-ids-javascript) – lusc Jun 14 '22 at 12:32
  • Thanks! I think it's better to use the discord tag. –  Jun 14 '22 at 12:36

1 Answers1

0

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)
})
koro
  • 111
  • 1
  • 13