【发布时间】:2022-01-16 01:44:59
【问题描述】:
我有一些问题。
我花了三天时间试图解决这个问题,但我没有成功。
我需要你的帮助。
我的错误代码是
C:\Discord Bot\My BOT\node_modules\discord.js\src\util\Util.js:415
if (typeof data !== 'string') throw new error(errorMessage);
^
RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
at Function.verifyString (C:\Discord Bot\My BOT\node_modules\discord.js\src\util\Util.js:415:41)
at Function.normalizeField (C:\Discord Bot\My BOT\node_modules\discord.js\src\structures\MessageEmbed.js:518:19)
at C:\Discord Bot\My BOT\node_modules\discord.js\src\structures\MessageEmbed.js:539:14
at Array.map (<anonymous>)
at Function.normalizeFields (C:\Discord Bot\My BOT\node_modules\discord.js\src\structures\MessageEmbed.js:538:8)
at MessageEmbed.addFields (C:\Discord Bot\My BOT\node_modules\discord.js\src\structures\MessageEmbed.js:324:42)
at MessageEmbed.addField (C:\Discord Bot\My BOT\node_modules\discord.js\src\structures\MessageEmbed.js:315:17)
at C:\Discord Bot\My BOT\src\commands\vatsim\atc.js:57:6
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
[Symbol(code)]: 'EMBED_FIELD_VALUE'
}
我的代码是
const Discord = require("discord.js")
const fetch = require('node-fetch');
module.exports.run = async (client, message, args) => {
var ICAO = message.content.split(' ').slice(1).join(' ').toUpperCase()
fetch(`https://data.vatsim.net/v3/vatsim-data.json`)
.then(response => response.json())
.then(data => {
let atc = data.controllers.find(Data => Data.callsign === `${ICAO}`);
let cid = atc.cid
let name = atc.name
let facility = atc.facility
let callsign = atc.callsign
let frequency = atc.frequency
let rating = atc.rating
let server = atc.server
let range = atc.visual_range
let atis = atc.text_atis
let last_update = atc.last_updated
let logon_time = atc.logon_time
const ok = new Discord.MessageEmbed()
.setColor('GREEN')
.setTitle(`????️ **${ICAO} - ATC INFO**`)
.addField('???? CID', cid, true)
.addField('???? NAME', name, true)
.addField('???? CALLSIGN', callsign, true)
.addField('????️ FREQUENCY', frequency, true)
.addField('✅ RATING', rating, true)
.addField('???? FACILITY', `FACILITY : ${fac}`, true)
.addField('????️ SERVER', `SERVER : ${server}`, true)
.addField('????️ RANGE', `RANGE : ${range}`, true)
.addField('✉️ TEXT ATIS', atis)
.addField('⏲️ LOGON_TIME', logon_time, true)
.addField('⏲️ LAST_UPDATE', last_update, true)
.setFooter(`Requested by ${message.author.username}#${message.author.discriminator} • Via VATSIM API`);
message.channel.send({embeds: [ok]})
}).catch(e => {
const fail = new Discord.MessageEmbed()
.setColor('RED')
.setTitle('❌ ERROR')
.setDescription(`The controller you found ${ICAO} is not online. Please check the callsign again!`)
.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`);
return message.channel.send({embeds: [fail]})
})
}
module.exports.config = {
name: "atc",
aliases: ['ATC']
}
我的 Discord.js 版本是 13.4.0 DEV
我尝试安装node-fetch ver 3.X 或以上,失败了。(使用Import)所以我目前使用的是2.6.1版本。
感谢您的帮助
【问题讨论】:
-
您知道,在 StackOverflow 上,语法高亮使用标签来查找正确的语言。
标签: javascript discord.js