如何解决这个问题,请告诉
how to fix this please tell
你好,我是 js 的新手,制作了一个 discord 机器人,现在正在制作 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 ()
在 Function.normalizeFields (/home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:564:8)
在 MessageEmbed.addFields (/home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:328:42)
在 MessageEmbed.addField (/home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:319:17)
在 Object.module.exports.run (/home/runner/js-try3/commands/minecraft/mcserverinfo.js:21:6) {
[符号(代码)]:'EMBED_FIELD_VALUE'
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
returns 承诺,使用 await
解决承诺
const fetch = require('node-fetch');
const response = await fetch(`https://api.mcsrvstat.us/2/${Ip}`);
const json = await response.json();
你好,我是 js 的新手,制作了一个 discord 机器人,现在正在制作 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 () 在 Function.normalizeFields (/home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:564:8) 在 MessageEmbed.addFields (/home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:328:42) 在 MessageEmbed.addField (/home/runner/js-try3/node_modules/discord.js/src/structures/MessageEmbed.js:319:17) 在 Object.module.exports.run (/home/runner/js-try3/commands/minecraft/mcserverinfo.js:21:6) { [符号(代码)]:'EMBED_FIELD_VALUE'
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
returns 承诺,使用 await
const fetch = require('node-fetch');
const response = await fetch(`https://api.mcsrvstat.us/2/${Ip}`);
const json = await response.json();