Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda