admin管理员组

文章数量:1431037

.avatarURL for discord.js is not displaying any image.

I'm trying to make a mand 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 mand _showpfp @user the bot will respond with

user's Profile Picture

and thats it...

.avatarURL for discord.js is not displaying any image.

I'm trying to make a mand 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 mand _showpfp @user the bot will respond with

user's Profile Picture

and thats it...

Share Improve this question asked Oct 7, 2019 at 5:07 user12174720user12174720 331 gold badge1 silver badge4 bronze badges 2
  • I forgot to mention in the post, but tmember is let tMember = message.mentions.members.first(); – user12174720 Commented Oct 7, 2019 at 5:10
  • You can edit the question to include this information. It's best to not create ments for additional information – T. Dirks Commented Oct 7, 2019 at 8:26
Add a ment  | 

1 Answer 1

Reset to default 2

The issue is that tMember doesn't have a property avatarURL. In your ment 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);
}

本文标签: javascriptIssue with Discordjs avatarURLStack Overflow