'How to find user by their id in discord.js
I want my bot to be able to give specific roles to specific users declared with their id. I tried:
const user = bot.users.cache.get(args[2]);
user.roles.add("[role ID]");
Solution 1:[1]
If you already have the user's ID, you can fetch the user object using the following code:
const client = new Discord.Client();
let thanos = client.users.fetch('IDHERE');
thanos.then(function(result1) {
//put your code that uses the result1 (the user object) here
//for example, you could do var imgURL = result1.displayAvatarURL();
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PPG tv |
