How To Get Specific Member Username With Discord.js
I would like to add one specific member information (username + avatar) into an embed message. Does someone know how to do that? const feedback = new discord.RichEmbed() .setColor(
Solution 1:
The following code must be modified to use the latest version of Discord.js (v12 at the time of this edit) due to the implementation of Managers.
You can retrieve a user by their ID from the client's cache of users, Client#users
. However, every user isn't guaranteed to be cached at all times, so you can fetch a user from Discord using Client#fetchUser()
. Keep in mind, it returns a Promise. If the user is in the cache, the method will return it.
Example:
// Async context needed for 'await'try {
const devID = '436577130583949315';
const dev = await client.fetchUser(devID);
const feedback = new discord.RichEmbed()
.setColor([0, 0, 255])
.setFooter(`Bot created by ${dev.tag}.`, dev.displayAvatarURL)
.setDescription('Your text here.');
await message.channel.send(feedback);
} catch(err) {
console.error(err);
}
Post a Comment for "How To Get Specific Member Username With Discord.js"