Hola, tengo un problema y es si (tipo de datos! == 'cadena') lanza un nuevo error (mensaje de error); RangeError [EMBED_FIELD_VALUE]: los valores del campo MessageEmbed no deben ser cadenas vacías.
Estoy tratando de que los jugadores pongan la cantidad de jugadores que tiene el servidor de Minecraft como:
Jugadores en línea: 79 jugadores
mi código es:
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], }); } }, );Modifique su código de su reciente:
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], }); } }, ); He visto muchos errores aquí, también puede usar un operador llamado or in operator || para evitar errores cuando los players llegan a 0 miembros.
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); } }, );EDITAR:
Probé su código y detecté un error como Error: Failed all 1 attempts
para que puedas usar la función .catch
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);