Reputation: 33
.avatarURL for discord.js is not displaying any image.
I'm trying to make a command for my discord bot that lets someone ping another and have the bot display their profile picture. I quickly homed in on .avatarURL being the solution for this, but it doesn't seem to be displaying any image at all. Any help would be appreciated.
if (message.content.startsWith(`${prefix}showpfp`)) {
let embed = new Discord.RichEmbed().setTitle(tMember.displayName + "'s Profile Picture").setImage(tMember.avatarURL).setColor('#add8e6')
message.channel.send(embed);
}
after typing in command _showpfp @user
the bot will respond with
user's Profile Picture
and thats it...
Upvotes: 0
Views: 10404
Reputation: 3676
The issue is that tMember
doesn't have a property avatarURL
. In your comment you say that you get the value of tMember
by doing message.mentions.members.first()
, however message.mentions.members
is a collection of GuildMembers. A GuildMember doesn't have a property avatarURL
.
However, the class User does have the property avatarURL
. Therefor you need to fetch the member as an instance of User first. Luckily for you, the class GuildMember has a property .user
which does just that.
So the fix for your problem is to change the parameter of the setImage
to tMember.user.avatarURL
, as can be seen below.
if (message.content.startsWith(`${prefix}showpfp`)) {
let embed = new Discord.RichEmbed().setTitle(tMember.displayName + "'s Profile Picture").setImage(tMember.user.avatarURL).setColor('#add8e6')
message.channel.send(embed);
}
Upvotes: 2