Reputation: 417
I am using discord.js for building a bot in nodejs. It is hosted in Replit. Below, is the code I am using to send a message, containing the sender's avatar. But, unfortunately, it doesn't work as expected ! (couldn't see the image ).
client.on("message", msg => {
if (msg.channel.name === 'bot-is-here') {
if (msg.content === "avatar") {
const embed = new Discord.MessageEmbed()
.setTitle('Avatar!')
.setAuthor("Your Avatar", msg.author.avatar)
.setImage(msg.author.avatar)
.setColor('RANDOM')
.setDescription('Avatar URL')
msg.reply(embed);
}
}
})
Any help is greatly appreciated !
Upvotes: 0
Views: 515
Reputation: 592
Avatar is a property of an User object which returns the ID of the user's avatar as a String. In order do get the avatar of the user, you need to do msg.author.avatarURL()
or msg.author.displayAvatarURL()
. The difference between these two is that, the avatarURL() method returns the avatar if the user, only if it's present. The displayAvatarURL() method returns the user's avatar if they have one. Otherwise a link to their default avatar will be returned.
Upvotes: 2