如何解决这个问题请告诉

穆罕默德·佐海布·乌尔·拉赫曼

您好,我是 js 新手,制作了一个不和谐的机器人,现在正在制作和 mc 服务器信息命令,但收到此错误 const json = await response.json(); ^

RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串。在 Function.verifyString (/home/runner/js-try3/node_modules/discord.js/src/util/Util.js:416:41) 在 Function.normalizeField (/home/runner/js-try3/node_modules/discord. js/src/structures/MessageEmbed.js:544:19) 在 /home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:565:14 在 Array.map () 在函数。 MessageEmbed.addFields (/home/runner/js-try3/node_modules/discord.js/src) 的 normalizeFields (/home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:564:8) /structures/MessageEmbed.js:328:42) 在 Object.module.exports 的 MessageEmbed.addField (/home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:319:17)。运行(/home/runner/js-try3/commands/minecraft/mcserverinfo.js:21:6){[符号(代码)]:'

const fetch = require('node-fetch')
const { MessageEmbed } = require('discord.js');

module.exports.run = async (Client, message, args, prefix) => {
  const Ip = args[0];
  if(!Ip) return
  message.reply('Please provide an Ip of a Minecraft java edition server');

  const response = fetch(`https://api.mcsrvstat.us/2/${Ip}`);
  const json = await response.json();

  if (!json.online) return
  message.reply('Hmm that dint work I guess you entered wrong ip or the server is offline');

  const info = new MessageEmbed()
  .setColor('RANDOM')
  .setTitle((json.hostname || Ip) + "Information")
  .setThumbnail(`https://eu.mc-api.net/v3/server/favicon/${Ip.toLowerCase()}`)
  .addField("Ip:", json.ip || "Unknown", false)
  .addField("Status:", json.online ?
           "Online": "Offline", false)
  .addField("port:", json.port || "Default", false)
  .addField('Version:', json.version || "Unknown", false)
  .addField("Players online:", json.players ? json.players.online : "Unknown", false)
  .addField("Max players allowed tto join at once:", json.players ? json.player.max: "Unknown", false)

  if(json.motd && json.motd.clean && json.motd.clean.length > 1)
    info.addField("Description:", json.motd.length >200? `${json.motd.clean.slice(0, 200)}...` : json.motd.clean);

  message.reply( { embeds:[info] } )
  
      }

module.exports.help = {
  name: 'mcserverinfo',
  aliases: []
}

有什么方法可以解决这个问题或任何其他方法而不是 .json 我们可以使用其他方法吗

阿泽

fetch返回一个承诺,通过使用解决承诺await

const fetch = require('node-fetch');
const response = await fetch(`https://api.mcsrvstat.us/2/${Ip}`);
const json = await response.json();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章