Reputation: 117
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([0, 0, 255])
.setFooter("Bot created by : " + message.author.username, message.author.avatarURL)
.setDescription("The text I want to be sent")
On the code above, I would like to change "message.author.username" and "message.author.avatarUrl" by a specific discord member identification id such as : 436577130583949315 for example.
However I don't know what is the way from that discord identification number to be able to show the username and the avatar.
Thanks in advance for your help :)
Upvotes: 2
Views: 32651
Reputation: 5623
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);
}
Upvotes: 4