javascript - TypeError: member is not a function when using `${member}`
问题描述
我有一个功能可以在用户加入时在 Discord 上发送随机选择的欢迎消息,并向其添加角色并且它曾经可以工作,但是在更新到 Discord.js v12 后,我收到了错误
Welcome ${member}, that will be 6,99 $. Wanna pay cash or credit card?
^
类型错误:成员不是函数*
当用户加入时。有人可以帮我吗?这是我的代码。
// When a member joins, this function executes.
bot.on('guildMemberAdd', (member) => {
console.log('User ' + member.id + ' has joined the guild.');
// Welcome messages possible options.
let welcomeMessages = [`${member}, welcome to our server :wave:!\n\nNow you're **one of us** :new_moon_with_face:! \n\n`,
`Welcome, ${member}. Hope you enjoy your stay.`, `Look who showed up... ${member}`, `Welcome ${member}, have a pleasant time.`,
`So... ${member} just arrived.`, `Great... ${member} is here!`, `Everyone stand up! ${member} is here.`, `Hello daddy ${member}...`
`Welcome ${member}, that will be 6,99 $. Wanna pay cash or credit card?`
];
let welcomeChannel = member.guild.channels.cache.get(serverData.welcomeChannelId);
let defaultRole = member.guild.roles.cache.get(serverData.defaultRoleId);
// Both the welcome message and GIFs will be chosen randomly.
let welcomeGif = welcomeGifs[Math.floor(Math.random() * welcomeGifs.length)];
let welcomeMessage = welcomeMessages[Math.floor(Math.random() * welcomeMessages.length)];
// This is the variable that stores the user profile picture for later use.
let newUserIcon = member.user.displayAvatarURL;
welcomeChannel.send(`${member}`);
// This is my embedded message, which allows loads of customization.
let welcomeMessageEmbed = new Discord.MessageEmbed()
.setColor(Math.floor(Math.random() * 16777214) + 1) // The color will be random.
.setDescription(welcomeMessage) // A message will be chosen randomly from the welcome messages tab.
.setImage(welcomeGif) // Same with the GIF.
.setThumbnail(newUserIcon) // The icon of the embedded message will be the user profile picture.
// Send in the embed.
welcomeChannel.send(welcomeMessageEmbed);
// This is the default role.
member.roles.add(defaultRole);
});
解决方案
member
是一个对象,你需要一个字符串。尝试member.displayName
在模板文字中使用。
推荐阅读
- c# - 杀死多个进程
- list - 如何反转地图中的值
> 颤抖? - javascript - Ionic 无法解析依赖树
- javascript - 将JS转换为cheerio的麻烦
- flutter - 未处理的异常:“IconData”类型不是“String”类型的子类型
- javascript - 如何在JS中的模板文字内传递字典
- scala - Monads - 扁平化的目的
- codeigniter - 如何根据环境设置不同的数据库连接-codeigniter 3
- jquery - 如果选中复选框,则显示 div,否则隐藏,除非选中“显示全部”复选框
- c# - 有没有办法在 C# 中对两个字节执行原子(读-更新-写)OR 操作?