我试图让我的discord.js机器人在有人加入时发送嵌入消息,并以pfp作为缩略图,但是它总是留下相同的错误。
代码:
bot.on('guildMemberAdd', member => {
// Send the message to a designated channel on a server:
const WelcomeChannel = member.guild.channels.cache.find(ch => ch.name === config.WelcomeChannelVar);
var newMember = member
// Do nothing if the channel wasn't found on this server
if (!WelcomeChannel) return;
const welcomeEmbed = new Discord.MessageEmbed()
.setTitle(newMember + 'joined!')
.addField('username', member)
.setColor(0x348a58)
.setThumbnail(newMember.showAvatarURL())
.setFooter('wow very nice profile bro')
WelcomeChannel.send(welcomeEmbed);
member.send("welcome to frogpond! read the rules :)");
});
错误:
TypeError: newMember.showAvatarURL is not a function
我已经尝试了一切。有人可以帮忙吗? 谢谢!
答案 0 :(得分:3)
我非常确定showAvatarURL()不是一个函数,而您的意思是avatarURL(),因此您应该将代码更改为:
const welcomeEmbed = new Discord.MessageEmbed()
// your stuff before thumbnail
.setThumbnail(newMember.user.avatarURL())
// your stuff after thumbnail
编辑:.user很重要,因为avatarURL只是一个User函数
答案 1 :(得分:2)
这是因为您写了showAvatarURL()
而不是displayAvatarURL()
。