Search code examples
javascriptdiscorddiscord.jsgamedig

MessageEmbed field values must be non-empty strings gamedig problem


Hello i have a problem and its its if (typeof data !== 'string') throw new error(errorMessage); RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.

i trying on players to put the amount of players that the minecraft server has like:

Players Online: 79 Players

my code its:


let state = null;

let jugadores = 0;

setInterval(() => {


  Gamedig.query({
    type: 'minecraft',
    host: 'mc.latinplay.net',
    port: '25565'
  })
  .then((updatedState) => {
    state = updatedState;
    players = state.players.length;
  });
}, 6000);

module.exports = new Command({
  name: cmdconfig.EstadoCommand,
  description: cmdconfig.EstadoCommandDesc,


  async run(interaction) {

      const LatinStatus = new Discord.MessageEmbed() 
    .setColor('RANDOM') 
       .addField('**Players:**', 'players')
      .addField('**Status**', "**Online💚**", true);
      interaction.reply({
        embeds: [LatinEstado],
      });
  
    }
  },
);

Solution

  • Modify your code from your recent:

    let state = null;
    
    let jugadores = 0;
    
    setInterval(() => {
    
    
      Gamedig.query({
        type: 'minecraft',
        host: 'mc.latinplay.net',
        port: '25565'
      })
      .then((updatedState) => {
        state = updatedState;
        players = state.players.length || "0"; //adding || operator so no error will occure
      });
    }, 6000);
    
    module.exports = new Command({
      name: cmdconfig.EstadoCommand,
      description: cmdconfig.EstadoCommandDesc,
    
    
      async run(interaction) {
    
          const LatinStatus = new Discord.MessageEmbed() 
        .setColor('RANDOM') 
           .addField('**Players:**', 'players')
          .addField('**Status**', "**Online💚**", true);
          interaction.reply({
            embeds: [LatinEstado],
          });
      
        }
      },
    );
    

    Ive seen alot of errors in here, you can also use an operator called or in operator || to prevent error when players reached on 0 members.

    module.exports = new Command({
      name: cmdconfig.EstadoCommand,
      description: cmdconfig.EstadoCommandDesc,
    
    
    async run(interaction) {
    let state = null;
    
    let jugadores = 0; //I also don't understand what is these for.
    
    setInterval(() => {
      Gamedig.query({
        type: 'minecraft',
        host: 'mc.latinplay.net',
        port: '25565'
      })
      .then((updatedState) => {
         state = updatedState;
         players = state.players.length;
         const LatinStatus = new Discord.MessageEmbed() 
        .setColor('RANDOM') 
        .addField('**Players:**', `${players}`) //also it must be `${players}`
        .addField('**Status**', "**Online💚**", true);
        interaction.reply({
          embeds: [LatinEstado],
        });
      });
    }, 6000);
        }
      },
    );
    

    EDIT:

    I tried your code and caught an error such as Error: Failed all 1 attempts

    so you can use .catch function

    setInterval(() => {
      Gamedig.query({
        type: 'minecraft',
        host: 'mc.latinplay.net',
        port: '25565'
      }).catch((err) => {
         console.log() //or
         console.log(err)
      })
      .then((updatedState) => {
         state = updatedState;
         players = state.players.length;
         const LatinStatus = new Discord.MessageEmbed() 
        .setColor('RANDOM') 
        .addField('**Players:**', `${players || "0"}`) //also it must be `${players}`
        .addField('**Status**', "**Online💚**", true);
        interaction.reply({
          embeds: [LatinEstado],
        });
      });
    }, 6000);