Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
I cant start my bot, it said SyntaxError: Identifier 'embed' has already been declared

here is the codes, im using replit discord.js

const config = require('./config');
const commands = require('./help');

let bot = new Client({
  fetchAllMembers: true, // Remove this if the bot is in large guilds.
  presence: {
    status: 'online',
    activity: {
      name: `${config.prefix} help`,
      type: 'LISTENING'
    }
  }
});

bot.on('ready', () => console.log(`Logged in as ${bot.user.tag}.`));

bot.on('message', async message => {
  // Check for command
  if (message.content.startsWith(config.prefix)) {
    let args = message.content.slice(config.prefix.length).split(' ');
    let command = args.shift().toLowerCase();

    switch (command) {
      case 'avatar':
        const Discord = require("discord.js");
        let user = message.mentions.users.first() || message.author;
        let avatar = user.displayAvatarURL({size: 4096, dynamic: true});
        let embed = new Discord.MessageEmbed()
        .setTitle(`Avatar de ${user.tag}` )
        .setURL(avatar)
        .setImage(avatar)
        .setColor('RANDOM')
        .setDescription('Ton avatar :')
        message.channel.send(embed)

      case 'ping':
        let msg = await message.reply('Pinging...');
        await msg.edit(`PONG! Message round-trip took ${Date.now() - msg.createdTimestamp}ms.`)
        break;

      case 'repeat':
        if (args.length > 0)
          message.channel.send(args.join(' '));
        else
          message.reply('You did not send a message to repeat, please try again.')
        break

      /* Unless you know what you're doing, don't change this command. */
      case 'help':
        let embed =  new MessageEmbed()
          .setTitle('Help Menu')
          .setColor('BLUE')
          .setFooter(`Requested by: ${message.member ? message.member.displayName : message.author.username}`, message.author.displayAvatarURL())
          .setThumbnail(bot.user.displayAvatarURL());
//29 more...

when ever i tried to start the bot, it said: 'SyntaxError: Identifier 'embed' has already been declared' then it crash, i also tried to make the embed to embed1 but it broke the code please someone help me on

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The variable embed is declared twice in the same scope. You have two options:

Option 1. Declare it once before the switch statement. Remember that all the cases of the switch are on the same scope.

let embed;
switch (command) {
    case 1:
        embed = new Embed();
        embed.doSomething();
        break;
    case 2:
        embed = new AnotherEmbed();
        break;
}

Option 2. Create a new scope for each case statement, by surrouning them with curly braces, and then declare that variable independently on each scope:

switch (command) {
    case 1: {
        const embed = new Embed();
        embed.doSomething();
        break;
    }
    case 2: {
        const embed = new AnotherEmbed();
        break;
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda