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

Discord.js v13 error: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings

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

ERROR:

[Photo Error]: https://i.stack.imgur.com/71eWe.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.



const { MessageEmbed } = require("discord.js")

module.exports = {
  name: "serverinfo",
  description: 'Gives Info About A Server',

  run: async (client, message, args) => {
    const { guild } = message
    const icon = message.guild.iconURL() // Icon Of Server
    const roles = message.guild.roles.cache.map(e => e.toString()) // Roles Of Server
    const emojis = message.guild.emojis.cache.map(e => e.toString()) // Emojis Of Server
    const emojicount = message.guild.emojis.cache
    const members = message.guild.members.cache // Members In Server
    const create = message.guild.createdAt.toLocaleDateString() // Server Create Date 

    let embed = new MessageEmbed()
      .setColor('RANDOM')
      .setTitle('Server Info')
      .setThumbnail(`${icon}`)
      .addField('Server Onwer:-', guild.owner)
      .addField('Server ID:-', guild.id)
      .addField('Server Creation Date:-', create)
      .addField('Boost Count:-', guild.premiumSubscriptionCount)
      .addField('Boost Level:-', guild.premiumTier)
      // You Can Add Any Emoji
      .addField('Member Count:-', `${members.size}\n${members.filter(member => !member.user.bot).size}(Human)\n${members.filter(member => member.user.bot).size}(BOT)`)
      .addField('Mmeber Stats:-', `${guild.members.cache.filter(member => member.presence.status == 'online').size}:-🟢\n${guild.members.cache.filter(member => member.presence.status == 'idle').size}:-🟡\n${guild.members.cache.filter(member => member.presence.status == 'dnd').size}:-🔴\n${guild.members.cache.filter(member => member.presence.status == 'offline').size}:-⚫\n`)
      .addField('Highest Role:-', guild.roles.highest)
      .addField('Roles:-', `${roles}`, true) // <true> Means All Roles Will Come In Line
      .addField('Emoji Count:-', `${emojicount.size}\n${emojicount.filter(emoji => !emoji.animated).size}(Non Animated)\n${emojicount.filter(emoji => emoji.animated).size}(Animated)`)
      .addField('Emojis:-', `${emojis}`, true) // <true> Means All Emojis Will Come In Line // This Will All Emojis Of Server
      // You Can Add Any Emoji
      .addField('Server Stats:-', `${guild.channels.cache.filter(channel => channel.type == 'text').size}⌨️\n${guild.channels.cache.filter(channel => channel.type == 'voice').size}🔈\n${guild.channels.cache.filter(channel => channel.type == 'news').size}📢\n${guild.channels.cache.filter(channel => channel.type == 'category').size}📁`)
      .setFooter('Server Info', icon)

    message.channel.send({ embeds:  })
    
  }
}


  [1]: https://i.stack.imgur.com/71eWe.png

>Solution :

The error comes from the fact that you are trying to access the owner property in the guild. The guild variable does not have this property. If you want to fetch the owner, you can either get their id by using this:

const ownerId = guild.ownerId

Or, if you want to fetch the owner’s complete details, you can use this:

const owner = await guild.fetchOwner()

I also noticed that you are trying to send numbers instead of strings in many places such as:

.addField('Boost Count:-', guild.premiumSubscriptionCount)
.addField('Member Count:-', `${members.size}\n${members.filter(member => !member.user.bot).size}(Human)\n${members.filter(member => member.user.bot).size}(BOT)`) // members.size is a number
.addField('Emoji Count:-', `${emojicount.size}\n${emojicount.filter(emoji => !emoji.animated).size}(Non Animated)\n${emojicount.filter(emoji => emoji.animated).size}(Animated)`) // emojicount.size is a number

and trying to send objects instead of strings like here =>

.addField('Highest Role:-', guild.roles.highest)

(the highest property is an object which contains the complete role, you can access the name by using highest.name). So in all these places, you can convert the numbers to strings by using template literals (by surrounding them with backticks `).

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