Discord.js V12 Userinfo createdAt / joinedAt undefined

Discord.js V12 Userinfo createdAt / joinedAt undefined

我是新手,边走边尝试学习,但我正在努力学习这段代码,我完全困惑了。 iv 设法使一切正常(最终),除了以下问题,.userinfo @randomUser 生成除

之外的所有用户详细信息

*注册日期 & *加入日期

删除这些行可以让其他一切正常工作。是否也可以显示用户角色?

TypeError: 无法读取未定义的 属性 'createdAt'

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")

.fetch 是一个异步函数,所以你需要使用 await.then,你已经有了 Userlet user = (m.mentions.users.first()) || m.author 的实例,所以为什么不用那个?

userinfo.registered = moment.gmt(user.createdAt);
userinfo.joined = moment.gmt(user.joinedAt);