我在 discord.js 中的 userinfo 命令只给出错误

My userinfo command in discord.js is giving only errors

我正在尝试创建 userinfo 命令,但它无法正常工作。只会出现如下错误: .join 不是函数或成员未定义。我的朋友也没有得到错误。谁能看一看?谢谢!

const discord = require('discord.js');
const moment = require('moment');

module.exports = {
    name: 'userinfo',
    description: 'let you see the info about you',
        usage: '[command name]',
    execute(message, args, client) {

        let user = message.mentions.users.first() || message.author;

        var roles = member.roles.cache.size - 1;
        var roleNames = member.roles.cache.map(r => r).join(" ").replace("@everyone", "");
        if(roles == 0) roleNames = "No roles";

    var embed = new discord.MessageEmbed()
    .setColor("RANDOM")
    .setThumbnail(message.author.avatarURL)
    .addField(`${user.tag}`, `${user}`, true)
    .addField("ID:", `${user.id}`, true)
    .addField("Roles:", message.member.roles.cache.some(roles => `${roles}`).join(', '), true)
    .addField("Joined The Server On:", `${moment.utc(member.joinedAt).format("dddd, MMMM Do YYYY")}`, true)
    .addField("Account Created On:", `${moment.utc(user.createdAt).format("dddd, MMMM Do YYYY")}`, true) 
    .addField("Roles:", member.roles.map(roles => `${roles}`).join(', '), true)

    message.channel.send(embed);
    }
};

您收到此特定错误是因为未定义成员变量。如果你想让你的代码工作,你可以添加 const member = message.member 到执行函数,它应该工作

对于想要代码的人:这是有效的,只检查头像字段!

 const discord = require('discord.js');
    const moment = require('moment');
    const { MessageEmbed } = require('discord.js');

module.exports = {
    name: 'userinfo',
    description: 'let you see the info about you',
        usage: '[command name]',
    execute(message, args, client) {

        let user = message.mentions.users.first() || message.author;
        const member = message.member

        var roles = member.roles.cache.size - 1;
        var roleNames = member.roles.cache.map(r => r).join(" ").replace("@everyone", "");
        if(roles == 0) roleNames = "No roles";

        const embed = new MessageEmbed()
    .setColor("RANDOM")
    .setThumbnail(message.author.avatarURL)
    .addField(`${user.tag}`, `${user}`, true)
    .addField("ID:", `${user.id}`, true)
    .addField("Roles:", message.member.roles.cache.map(roles => `${roles}`).join(', '), true)
    .addField("Joined The Server On:", `${moment.utc(member.joinedAt).format("dddd, MMMM Do YYYY")}`, true)
    .addField("Account Created On:", `${moment.utc(user.createdAt).format("dddd, MMMM Do YYYY")}`, true) 

    message.reply({ embeds: [embed], ephemeral: true });
    }
};