[英]Discord.js v13 [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings
[英][Discord.js]MessageEmbed field values must be non-empty strings
我有一些問題。
我花了三天時間試圖解決這個問題,但我沒有成功。
我需要你的幫助。
我的錯誤代碼是
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 版本。
感謝您的幫助
提取的一些值是數字,但嵌入僅將非空字符串作為字段的前 2 個 arguments。
您需要獲取未連接到字符串的 2 個值的字符串,如下所示:
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', String(cid), true) // Here
.addField('📛 NAME', name, true)
.addField('🛑 CALLSIGN', callsign, true)
.addField('🛰️ FREQUENCY', frequency, true)
.addField('✅ RATING', String(rating), true) // Here
.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']
}
將字段值轉換為字符串
const ok = new Discord.MessageEmbed()
.setColor('GREEN')
.setTitle(`🗨️ **${ICAO} - ATC INFO**`)
.addField('📡 CID', cid?.toString(), true)
.addField('📛 NAME', name.toString(), true)
.addField('🛑 CALLSIGN', callsign.toString(), true)
.addField('🛰️ FREQUENCY', frequency.toString(), true)
.addField('✅ RATING', rating.toString(), true)
.addField('🆓 FACILITY', `FACILITY : ${fac.toString()}`, true)
.addField('🛰️ SERVER', `SERVER : ${server.toString()}`, true)
.addField('🗺️ RANGE', `RANGE : ${range.toString()}`, true)
.addField('✉️ TEXT ATIS', atis.toString())
.addField('⏲️ LOGON_TIME', logon_time.toString(), true)
.addField('⏲️ LAST_UPDATE', last_update.toString(), true)
.setFooter(`Requested by ${message.author.username}#${message.author.discriminator} • Via VATSIM API`);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.