bot.on('guildMemberAdd', (guildMember, channel, message) => {
guildMember.addRole(guildMember.guild.roles.find(role => role.name === "ew"));
embed = new discord.RichEmbed()
.setTitle("User Join Notification")
.setDescription(guildMember.username + " has joined this server.")
.setColor("#21a1e1")
guildMember.guild.channels.get('430681100956991511').send(embed);
});
每当玩家加入服务器时,它都会显示 undefined已加入此服务器而非实际用户名。
我怎么能纠正这个问题?
感谢。
答案 0 :(得分:1)
根据我对the Discord.JS doc的理解,guildMember
没有username
,但它有user
个对象,其本身包含username
.setDescription(guildMember.user.username + " has joined this server.")
或者,可以使用guildMember.nickname
,但只有在guildMember
配置了一个bookings(id,lessons_id,users_id)
lessons(id,name,date,max_enrollments,enrollments)
permits(id,user_id,used_entries,entries)
时它才会起作用,所以它有时仍会显示未定义。