Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I’m working on a serverinfo command in discord.js v13 and I don’t know how to fix this error

ERROR:

[Photo Error]: https://i.stack.imgur.com/tcEem.png

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if (typeof data !== ‘string’) throw new error(errorMessage);
^

RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.

[Symbol(code)]: ‘EMBED_FIELD_VALUE’


const { Client, MessageEmbed, Message } = require(`discord.js`);
const moment = require(`moment`)

module.exports = {
  name: "serverinfo",
  description: "Get server information",
  /**
  *
  * @param {Client} client 
  * @param {Message} message
  * @param {String[]} args
  */
  run: async (client, message, args) => {
    const guild = message.guild;
    let embed = new MessageEmbed()
      .setTitle(message.guild.name)
      .setThumbnail(message.guild.iconURL())
      .setColor("RANDOM")
      .addField(`General Info`, [
        `ID: ${guild.id}`,
        `Name: ${guild.name}`,
        `Owner: ${guild.owner}`,
      ])
      .addField("Counts", [
        `Role: ${guild.roles.cache.size} roles`,
        `Channel: ${guild.channel.cache.size
        } total (Text: ${guild.channel.cache.filter(
          (ch) => ch.type === "text"
        ).size}, Voice: ${guild.channel.cache.filter(
          (ch) => ch.type === "Voice"
        )})`,
        `Emojis: ${guild.emojis.cache.size} (Regular: ${guild.emojis.cache.filter((e) => !e.animated).size
}, Animated: ${
  guild.emojis.cache.filter((e) => !e.animated).size
})`,
    ])
    .addField("Additional Information", [
      `Created: ${
  moment(guild.createdTimestamp).format(
    `LT`
  )
} ${ moment(guild.createdTimestamp).format(`LL`) } ${
  moment(
    guild.createdTimestamp
  ).fromNow()
} `,
      `Region: ${ guild.region } `,
      `Boost Tier: ${
  guild.premiumTier ? `Tier ${guild.premiumTier}` : "None"
} `,
      `Boost Count: ${guild.premiumSubscribtionCount || "0"}`,
    ]);

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

>Solution :

The second parameter to .addField must be a string, as your error message says:

MessageEmbed field values must be non-empty strings.

You pass an array, which is not a "non-empty string". I.e.

let embed = new MessageEmbed()
.addField('foo', 'bar')

is fine.

let embed = new MessageEmbed()
.addField('foo', ['bar', 'baz'])

is not.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading