Im new to this and trying learn as i go here but im struggling with this code, im totally confused. iv managed to get everything working (eventually) except from the following issues, .userinfo @randomUser produces all the users details apart from
*date registered & *date joined
removing these lines allow everything else to work fine. Is it also possible to display users roles?
ERROR
userinfo.registered = moment.gmt(m.guild.members.fetch(user.id).user.createdAt); ^
TypeError: Cannot read property 'createdAt' of undefined
const Discord = require("discord.js");
const moment = require("moment");
const bot = new Discord.Client({ disableEveryone: true});
bot.on("ready", () => console.log(`Connected to Discord!`))
bot.on("message", m => {
let prefix = ".";
if (m.author.bot || !m.guild) return;
if (!m.content.startsWith(prefix)) return;
if (m.content.startsWith(prefix + "userinfo")) {
let user = (m.mentions.users.first()) || m.author;
let member = m.mentions.members.first() || m.member;
let userinfo = {};
userinfo.avatar = user.displayAvatarURL()
userinfo.name = user.username;
userinfo.discrim = `#${user.discriminator}`;
userinfo.id = user.id;
userinfo.status = user.presence.status;
userinfo.registered = moment.gmt(m.guild.members.fetch(user.id).user.createdAt);
userinfo.joined = moment.gmt(m.guild.members.fetch(user.id).joinedAt);
const embed = new Discord.MessageEmbed()
.setAuthor(user.tag, userinfo.avatar)
.setThumbnail(userinfo.avatar)
.addField(`Username`, userinfo.name, true)
.addField(`Discriminator`, userinfo.discrim, true)
.addField(`Status`, userinfo.status, true)
.addField(`ID`, userinfo.id)
.addField(`Registered`, userinfo.registered)
.addField(`Joined`, userinfo.joined)
return m.channel.send(embed);
}
});
bot.login("XXX")