Reputation: 23
I want to fetch the avatar picture of the person who sends the message through a Discord bot. Like the author of the message.
This is my code:
case 'embed':
const embed = new Discord.MessageEmbed()
.setAuthor(`From ${message.author.username}`, message.author.avatarURL)
.setDescription("My Description");
message.channel.send(embed);
break;
It returns the author's username correctly through message.author.username
but when I am using message.author.avatarURL
it's not returning anything. I had tried to use message.author.defaultAvatarURL
and it works perfectly. But I don't know why avatarURL doesn't show up anything.
Upvotes: 2
Views: 1412
Reputation: 6816
In discord.js v12 User#avatarURL
is a method, not a property, and so you need to call it to get the URL. You can also use User#displayAvatarURL
to get the either the actual displayed avatar (it links to the default avatar if necessary). Here's an example:
.setAuthor(`From ${message.author.username}`, message.author.avatarURL())
.setAuthor(`From ${message.author.username}`, message.author.displayAvatarURL())
Upvotes: 1