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
1 Answer
Reset to default 2The 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
版权声明:本文标题:javascript - Issue with Discord.js avatarURL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745553297a2663042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论