Johonny
Johonny

Reputation: 151

Discord.js how to get user id just from the username

This isn't working: client.users.cache.get(`${args[0]}`).id;

What should I do to fix it? I'm on v12

Upvotes: 1

Views: 1466

Answers (1)

G3ru1a
G3ru1a

Reputation: 93

Try

matching_client = client.users.cache.filter(user => user.username === args[0]);

matching_client is a Collection of users that match that username

Relevant documentation link:

https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=filter

Upvotes: 1

Related Questions