This is my simple code. and i need optional fields (fd, fdd) on my slesh command embed builder. how can i do?empty fields no delete so.if my field value is empty, then don't show up, and if the field is have a value then add on embed. optional values.
const desc = options.getString("leírás");
const fd1 = options.getString("field1");
const fd2 = options.getString("field2");
const fd3 = options.getString("field3");
const fdd1 = options.getString("fielddesc1");
const fdd2 = options.getString("fielddesc2");
const fdd3 = options.getString("fielddesc3");
//cache.find(role => role.id === "967822275355246732");A
const Response = new MessageEmbed()
.setColor("RANDOM")
.setDescription(`${interaction.member} létrehozott egy <@&963762743150796810>-t, **${type}** kategóriával.`)
.setThumbnail('https://media.discordapp.net/attachments/967828295121006592/969690574674354337/958794200999145513.png')
.addField("⟬Cím⟭", `${title}`)
.addField("⟬Leírás⟭", `${desc}`)
.addField(`${fd1}`, `${fdd1}`)
.addField(`${fd1}`, `${fdd1}`)
.addField(`${fd2}`, `${fdd2}`)
.addField(`${fd3}`, `${fdd3}`)
.setFooter({text: "*`Telihold, Tele mosoly :)`*"})
.setTimestamp()
const message = await interaction.reply({embeds: [Response], fetchReply: true});
message.react('🔥')
.then(() => message.react('❤️'))
.catch(error => console.error('Nem tudom betölteni az egyik hangulatjelet', error));
}
}
///i tried this way but not good///
.addField("⟬Cím⟭", `${title}`)
.addField("⟬Leírás⟭", `${desc}`)
.setFooter({text: "*`Telihold, Tele mosoly :)`*"})
.setTimestamp()
const message = await interaction.reply({embeds: [Response], fetchReply: true});
message.react('🔥')
.then(() => message.react('❤️'))
.catch(error => console.error('Nem tudom betölteni az egyik hangulatjelet', error));
if (`${fd1}`)
Response.addField(`${fd1}`, `${fdd1}`)
if (`${fd2}`)
Response.addField(`${fd1}`, `${fdd1}`)
if (`${fd3}`)
Response.addField(`${fd1}`, `${fdd1}`)
return interaction.reply({embeds: [Response], fetchReply: true});
Use an if statement to check if the variable exists first.
let Response = new MessageEmbed()
.setColor("RANDOM")
.setDescription(` egy <@&963762743150796810>-t, kategóriával.`)
.setThumbnail('https://media.discordapp.net/attachments/967828295121006592/969690574674354337/958794200999145513.png')
.addField("⟬Cím⟭", `abc`)
.addField("⟬Leírás⟭", `def`)
.setFooter({ text: "*`Telihold, Tele mosoly :)`*" })
.setTimestamp()
if (fd1) {
Response.addField(`${fd1}`, `${fdd1}`)
}
Then you will be able to avoid it saying "null" when the variable isn't set.