简体   繁体   English

MessageEmbed 字段值必须是非空字符串 gamedig 问题

[英]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);你好我有一个问题,它的 if (typeof data !== 'string') throw new error(errorMessage); RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings. RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串。

i trying on players to put the amount of players that the minecraft server has like:我尝试让玩家输入我的世界服务器拥有的玩家数量:

Players Online: 79 Players在线玩家:79 名玩家

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],
      });
  
    }
  },
);

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 ||我在这里看到了很多错误,你也可以使用一个叫做or in operator ||的运算符to prevent error when players reached on 0 members.以防止players到达0个成员时出错。

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我尝试了您的代码并发现了一个错误,例如Error: Failed all 1 attempts

so you can use .catch function所以你可以使用.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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MessageEmbed 字段值必须是非空字符串 - MessageEmbed field values must be non-empty strings [Discord.js]MessageEmbed 字段值必须是非空字符串 - [Discord.js]MessageEmbed field values must be non-empty strings Discord.js v13 错误:RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串 - Discord.js v13 error: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings Discord bot 无法创建嵌入 RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串 - Discord bot not able to create the embed RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings discord.js V.13 嵌入问题 - RangeError [EMBED_FIELD_NAME]:MessageEmbed 字段名称必须是非空字符串。 - 特别是“成员自:”字段 - discord.js V.13 Embed Issue - RangeError [EMBED_FIELD_NAME]: MessageEmbed field names must be non-empty strings. - Specifically "Member Since:" field 消息内容必须是非空字符串 MessageEmbed - Message Content Must Be A Non-Empty String MessageEmbed MessageEmbed 字段值不能为空 - MessageEmbed field values may not be empty Javascript:非空字符串的“真实”值 - Javascript: “truthy” values for non-empty strings ESLint 7.1.0 错误:“模式”必须是非空字符串或非空字符串数组 - ESLint 7.1.0 Error: 'patterns' must be a non-empty string or an array of non-empty strings 键必须是非空字符串,并且不能包含“.”、“#”、“$”、“/”、“[”或“]” - Keys must be non-empty strings and can't contain “.”, “#”, “$”, “/”, “[”, or “]”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM