skip to Main Content

This is an embed builder discord.js v14
can anyone make it simpler ??

const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('embed')
        .setDescription('Send a message in an embed')
        
        .addStringOption(option =>
            option.setName('line1')
                .setDescription('The first line of text for the embed')
                .setRequired(true))
        .addStringOption(option =>
            option.setName('line2')
                .setDescription('The second line of text for the embed')
                .setRequired(false))
        .addStringOption(option =>
            option.setName('line3')
                .setDescription('The third line of text for the embed')
                .setRequired(false))
        .addStringOption(option =>
            option.setName('line4')
                .setDescription('The fourth line of text for the embed')
                .setRequired(false))
        .addStringOption(option =>
            option.setName('line5')
                .setDescription('The fifth line of text for the embed')
                .setRequired(false))
        .addStringOption(option =>
            option.setName('line6')
                .setDescription('The sixtsh line of text for the embed')
                .setRequired(false))
        .addStringOption((option) => 
            option.setName('title')
                .setDescription('The Title Of Your Embed')
                .setRequired(false))
        .addStringOption(option =>
            option.setName('image')
                .setDescription('The image to display in the embed')
                .setRequired(false)),

    async execute(interaction) {
        const embedTitle = interaction.options.getString('title');
        const image = interaction.options.getString('image');
        const line1 = interaction.options.getString('line1');
        const line2 = interaction.options.getString('line2');
        const line3 = interaction.options.getString('line3');
        const line4 = interaction.options.getString('line4');
        const line5 = interaction.options.getString('line5');
        const line6 = interaction.options.getString('line6');

        const descriptionParts = [];

if (line1) {
  descriptionParts.push(`> **${line1}**`);
}

if (line2) {
  descriptionParts.push(`> **${line2}**`);
}

if (line3) {
  descriptionParts.push(`> **${line3}**`);
}

if (line4) {
  descriptionParts.push(`> **${line4}**`);
}

if (line5) {
  descriptionParts.push(`> **${line5}**`);
}

if (line6) {
    descriptionParts.push(`> **${line6}**`);
  }

const embed = new EmbedBuilder()
  .setColor('Gold')
  .setDescription(descriptionParts.join('nn'));

      if (embedTitle) {
        embed.setTitle(embedTitle)
      }

        if (image) {
            if (image.startsWith('http')) {
                embed.setImage(image);
            } else {
                return interaction.reply({ content: 'Invalid image URL provided.',  ephemeral: true});
            }
        }

      await interaction.reply({ content: 'Done Sending The Embed 🟢', ephemeral: true })

      await interaction.channel.send({ embeds:  });
    },
};

I want to make The Command More Simpler
can anyone make it simpler
so the user won’t select 99 lines
i don’t have a specific idea about the method that the command should work like it, but can anyone help me make it more simpler ??

I want to make The Command More Simpler
can anyone make it simpler
so the user won’t select 99 lines
i don’t have a specific idea about the method that the command should work like it, but can anyone help me make it more simpler ??

I want to make The Command More Simpler
can anyone make it simpler
so the user won’t select 99 lines
i don’t have a specific idea about the method that the command should work like it, but can anyone help me make it more simpler ??

2

Answers


  1. You can make a loop instead of conditions:

    for (let i = 1; i <= 6; i++) {
      const line = eval(`line${i}`);
      if (line) {
        descriptionParts.push(`> **${line}**`);
      }
    }
    
    Login or Signup to reply.
  2. One word: Modals.

    Instead of using a load of command options you could make the command trigger a modal with a paragraph text input. This approach is a lot simpler

    Here’s an example:

    const { ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
    
    client.on(Events.InteractionCreate, async interaction => {
        if (!interaction.isChatInputCommand()) return;
    
        if (interaction.commandName === 'ping') {
            // Create the modal
            const modal = new ModalBuilder()
                .setCustomId('myModal')
                .setTitle('My Modal');
    
            // Add components to modal
    
            // Create the text input components
            const favoriteColorInput = new TextInputBuilder()
                .setCustomId('favoriteColorInput')
                // The label is the prompt the user sees for this input
                .setLabel("What's your favorite color?")
                // Short means only a single line of text
                .setStyle(TextInputStyle.Short);
    
            const hobbiesInput = new TextInputBuilder()
                .setCustomId('hobbiesInput')
                .setLabel("What's some of your favorite hobbies?")
                // Paragraph means multiple lines of text.
                .setStyle(TextInputStyle.Paragraph);
    
            // An action row only holds one text input,
            // so you need one action row per text input.
            const firstActionRow = new ActionRowBuilder().addComponents(favoriteColorInput);
            const secondActionRow = new ActionRowBuilder().addComponents(hobbiesInput);
    
            // Add inputs to the modal
            modal.addComponents(firstActionRow, secondActionRow);
    
            // Show the modal to the user
            await interaction.showModal(modal);
        }
    });
    

    There’s a full Modals guide on the DiscordJS documentation page to help you get started: Modals | discord.js Guide

    Hope this helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search