Home > OS >  Why I keep getting an error when using embed?
Why I keep getting an error when using embed?

Time:04-04

I was trying to get a data using Axios, the problem is I always getting an error MessageEmbed field values must be non-empty strings. How can I fix this? This is what I tried

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]})`

CodePudding user response:

It might be there's no data for one of the value in your embed, to prevent this kind of error. You will need to put || "No data" in every value

{name: "Wind:", value: ${res.data.current.wind_mph || "No data"}`, inline: true})
  • Related