Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Optional functions in a discord.js embed

I made a command that creates an embed based on a message in discord such as:

!embed #FF0000 - Hello - World - https:/random_image.png

but how can I make a parameter optional, for example make an embed without image

const Discord = require("discord.js");

module.exports = {
    name: "embed",
    description: "Genera un embed en base a un imput",
    permissions: ["BAN_MEMBERS"],
    
    async execute(client, message, args, discord) {

        if (! message.member.permissions.has("BAN_MEMBERS")) return message.channel.send("No tienes permiso para usar este comando.")

        const msgcontent = args.join(" ");
        const msgsplit = msgcontent.split(' - ');
        const color = msgsplit[0]
        const title = msgsplit[1]
        const description = msgsplit[2]
        const image = msgsplit[3]

        if(!color) return message.channel.send('¡Ingresa el codigo HEX que quieres en tu embed!');
        if(!title) return message.channel.send("¡Ingresa el título que quieres en tu embed!");
        if(!description) return message.channel.send("Ingresa la descripción que quieres en tu embed!");
        if (!image) return message.channel.send("Ingresa el link de la imagen que quieres en tu embed!")

        const embed = new Discord.MessageEmbed()
        .setColor(`${color}`)
        .setTitle(`${title}`)
        .setDescription(`${description}`)
        .setImage(`${image}`)

        message.channel.send({ embeds: [embed] });

    }
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If the image field is empty, you can create a new embed without it. Kind of like this

    if(image === undefined){

const embed = new Discord.MessageEmbed()
        .setColor(`${color}`)
        .setTitle(`${title}`)
        .setDescription(`${description}`)

        message.channel.send({ embeds: [embed] });

}

Or state the embed before and then use the return function.

   if(image === undefined) return message.channel.send({ embeds: [embed] });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!