I’m using node and visual studio code. The script runs fine and the text gets embedded right below the title of the field. But instead of showing the joined server date, it shows ‘undefined’.

switch(args[0]){
case 'userinfo':         
     let usera = message.mentions.users.first()
     if(!usera) return message.channel.send("Must specify user")
     const joinDiscord = moment(user.createdAt).format('llll')

          let embed = new Discord.MessageEmbed()
          .setAuthor(usera.tag, usera.avatarURL)
          .addField("ID", usera.id, true)
          .addField("Username", usera.username, true)
          .addField("Status", usera.presence.status, true)
          .addField("Joined Server",usera.joinedAt, true)//its this part
          .addField("Created", usera.createdAt, true)
          .addField("Bot", usera.bot, true)
          .setTimestamp()
          .setColor(0x0f7fa6)
          .setThumbnail(usera.displayAvatarURL())
     message.channel.send({embed});
                        
}
});

Answer

joinedAt is a varible for the guildMember object type, but what you have is a user object. You can get the member object from the user object by doing the following:

switch(args[0]){
case 'userinfo':         
     let usera = message.mentions.users.first()
     if(!usera) return message.channel.send("Must specify user")
     const joinDiscord = moment(user.createdAt).format('llll')

          let embed = new Discord.MessageEmbed()
          .setAuthor(usera.tag, usera.avatarURL)
          .addField("ID", usera.id, true)
          .addField("Username", usera.username, true)
          .addField("Status", usera.presence.status, true)
          .addField("Joined Server",message.guild.members.cache.get(usera.id).joinedAt, true)//got the guild member from the users id
          .addField("Created", usera.createdAt, true)
          .addField("Bot", usera.bot, true)
          .setTimestamp()
          .setColor(0x0f7fa6)
          .setThumbnail(usera.displayAvatarURL())
     message.channel.send({embed});
                        
}
});

Write a comment

Your email address will not be published. Required fields are marked *