简体   繁体   中英

discord.js V.13 Embed Issue - RangeError [EMBED_FIELD_NAME]: MessageEmbed field names must be non-empty strings. - Specifically "Member Since:" field

I'm working on a user information command in discord.js V.13, but I just can't seem to get it to work.** **The error is centered around my "Member Since:" field.

Photo Error: 错误作为照片(请转成全文错误)

Written Error:

if (typeof data !== 'string') throw new error(errorMessage);

RangeError [EMBED_FIELD_NAME]: MessageEmbed field names must be non-empty strings.

const { CommandInteraction, Client, MessageEmbed } = require(`discord.js`);
const moment = require("moment");
const emoji = [
    { name: "DISCORD_EMPLOYEE", emoji: "<:Staff:994985083633160272>" },
    { name: "DISCORD_CERTIFIED_MODERATOR", emoji: "<:CertifiedModerator:994985105724551218>" },
    { name: "PARTNERED_SERVER_OWNER", emoji: "<:ServerPartner:994985085780643850>" },
    { name: "HYPESQUARD_EVENTS", emoji: "<:HypeSquardEvents:994985103824523296>" },
    { name: "HOUSE_BRAVERY", emoji: "<:HouseBraveryMember:994985087856820345>" },
    { name: "HOUSE_BRILLIANCE", emoji: "<:HouseBrillianceMember:994985091883348048>" },
    { name: "HOUSE_BALANCE", emoji: "<:HouseBalanceMember:994985089949777920>" },
    { name: "BUGHUNTER_LEVEL_1", emoji: "<:BugHunterLvL1:994985107939147936>" },
    { name: "BUGHUNTER_LEVEL_2", emoji: "<:BigHunterLvL2:994985101580566588>" },
    { name: "EARLY_VERIFIED_BOT_DEVELOPER", emoji: "<:VerifiedDeveloper:994985099135295529>" },
    { name: "EARLY_SUPPORTER", emoji: "<:EarlyNitroSupporter:994985096706801915>" }
  ];

module.exports = {
    name: `userinfo`,
    description: `Get a persons user information`,
    permission: "ADMINISTRATOR",
    usage: "/userinfo [USER]",
    options: [{
        name: 'user',
        type: 'USER',
        description: 'Select a user',
        required: true,
    }],
    /**
     * @param {CommandInteraction} interaction
     * @param {Client} client
     */
    async execute(interaction, client) {
        const user = interaction.options.getUser('user')
        await user.fetch();
        const flags = user.flags.toArray();

        let badges = [];
          emoji.forEach((e) => {
            if (flags.includes(e.name)) badges.push(e.emoji);
          });
        const startMessage = new MessageEmbed()
            .setTitle(`${user.tag}`)
            .setColor("BLURPLE")
            .setDescription(`**Badges:** ${badges.join(" ")}`)
            .setThumbnail(user.avatarURL({ dynamic: true }))
            .addField({ name: 'ID:', value: `\`\`\`${user.id}\`\`\`` })
            .addField({ name: "Member Since:", value: `\`\`\`<t:${parseInt(member.joinedAt / 1000)}:R>\`\`\``, inline: true })
            .addField('Nickname:', `\`\`\`${user.nickname || "False"}\`\`\``, true)
            .addField('Bot Account:', `\`\`\`${user.bot ? "True" : "False"}\`\`\``, true)
            .addField('Discriminator:', `\`\`\`#${user.discriminator}\`\`\``, true)
            .addField('Nitro:', `${user.premiumSubscriptionCount ? '\`\`\`Yes\`\`\`' : '\`\`\`No\`\`\`'}`,true)
            .addField("Banner:", `${user.bannerURL() ? "\`\`\`True\`\`\`" : "\`\`\`False\`\`\`"}`, true)
            .addField('Discord Account Created at:', `\`\`\`${moment(user.createdAt).format('MMM Do YYYY')}\`\`\``, true)
            .setImage(user.bannerURL({ dynamic: true, size: 512 }) || "")
        await interaction.reply({ embeds: [startMessage] });
    }
}
            .addField({ name: 'ID:', value: `\`\`\`${user.id}\`\`\`` })
            .addField({ name: "Member Since:", value: `\`\`\`<t:${parseInt(member.joinedAt / 1000)}:R>\`\`\``, inline: true })

There's a clear errore here as you are trying to add a field using an object as first and only variable passed, when it needs 3 as done under these two lines. Therefore it can't find a string, and tells you that the field name can't be empty

This is quite a simple debug process that took less than 20 seconds look more into the code for this errors, that should be signaled by a good IDE too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM