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
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 }); }, };
Advertisement
Answer
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.