需要帮助在我的Discord bot上配置加入消息

时间:2018-04-05 01:08:24

标签: node.js bots discord discord.js

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已加入此服务器而非实际用户名。

我怎么能纠正这个问题?

感谢。

1 个答案:

答案 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) 时它才会起作用,所以它有时仍会显示未定义。