为什么我在使用嵌入时总是出错?
Why I keep getting an error when using embed?
我试图使用 Axios 获取数据,问题是我总是收到错误 MessageEmbed field values must be non-empty strings.
我该如何解决这个问题?这是我试过的
const embed = new MessageEmbed()
.setTitle(${res.data.current.condition.text})
.setColor("RANDOM")
.setThumbnail(https:${res.data.current.condition.icon})
.setTimestamp()
.setFooter({text: Last Update: ${res.data.current.last_updated}})
.addFields(
{name: "Location:", value: ${res.data.location.name}, inline: true},
{name: "Region:", value:${res.data.location.region}, inline: true},
{name: "Country:", value: ${res.data.location.country}, inline: true},
{name: "Temperature:", value: ${res.data.current.temp_f}, inline: true},
{name: "Wind:", value: ${res.data.current.wind_mph}`, inline: true} )
message.channel.send({embeds: [embed]})`
可能是您嵌入的值之一没有数据,以防止出现此类错误。您需要将 || "No data"
放入每个值
{name: "Wind:", value: ${res.data.current.wind_mph || "No data"}`, inline: true})
我试图使用 Axios 获取数据,问题是我总是收到错误 MessageEmbed field values must be non-empty strings.
我该如何解决这个问题?这是我试过的
const embed = new MessageEmbed()
.setTitle(${res.data.current.condition.text})
.setColor("RANDOM")
.setThumbnail(https:${res.data.current.condition.icon})
.setTimestamp()
.setFooter({text: Last Update: ${res.data.current.last_updated}})
.addFields(
{name: "Location:", value: ${res.data.location.name}, inline: true},
{name: "Region:", value:${res.data.location.region}, inline: true},
{name: "Country:", value: ${res.data.location.country}, inline: true},
{name: "Temperature:", value: ${res.data.current.temp_f}, inline: true},
{name: "Wind:", value: ${res.data.current.wind_mph}`, inline: true} )
message.channel.send({embeds: [embed]})`
可能是您嵌入的值之一没有数据,以防止出现此类错误。您需要将 || "No data"
放入每个值
{name: "Wind:", value: ${res.data.current.wind_mph || "No data"}`, inline: true})