使用以下代码,我试图更改用户角色,然后获取用户名,以便可以将其发送给特定频道的消息。但是,它会继续在生成的消息中为用户名返回Undefined。

client.on('guildMemberAdd', guildMember => {
    // Set the member's roles to a new single role
    const GuildObj = guildMember.guild
    if (GuildObj.name = "GuildName") {
        guildMember.setRoles(['387154651365113866']).catch(console.error);
        client.guilds.get('308190520994430976').channels.get("593021188838522900").send("Welcome to the server " + guildMember.username + " you have successfully been given the role of lvl 1.")
    }
});

最佳答案

我认为这是因为username不是GuildMember的属性,而是nickname

client.channels.get("593021188838522900").send("... " + guildMember.nickname + "...")

10-08 15:52