Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  164] [ 6]  / answers: 1 / hits: 9690  / 5 Years ago, mon, october 7, 2019, 12:00:00

.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...


More From » bots

 Answers
2

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);
}

[#6023] Thursday, October 3, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breap

Total Points: 606
Total Questions: 96
Total Answers: 108

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
breap questions
Thu, Jun 24, 21, 00:00, 3 Years ago
Wed, Mar 18, 20, 00:00, 4 Years ago
Wed, Sep 18, 19, 00:00, 5 Years ago
;