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

115
Visualizações
How do I use multiple filters with awaitMessages?

I'm making a trivia-like game for a discord bot, but I'm having trouble figuring out how I can use multiple filters since I keep getting this error.

SyntaxError: Identifier 'filter' has already been declared

Here's my code (only the first 2 cases)

  case 0:
    const LGEmbed0 = new Discord.MessageEmbed()
      .setTitle("Guess the Level!")
      .setDescription("Difficulty: Medium")
      .setColor("#36ff69")
      .setImage(
        "https://media.discordapp.net/attachments/891672414361112616/892153208082923520/fever.PNG"
      )
      .setFooter(
        `Requested by ${message.author.username}`,
        `https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.webp`
      )
      .setTimestamp();
    console.log("Answer: Fever");
    message.channel.send({
      embeds: [LGEmbed0],
    });

    const filter = (m) => m.content.startsWith("Fever");

    message.channel
      .awaitMessages({ filter, max: 1, time: 10000, errors: ["time"] })
      .then((collected) => message.channel.send({ embeds: [cor] }))
      .catch((collected) => message.channel.send({ embeds: [time] }));

    break;

  case 1:
    const LGEmbed1 = new Discord.MessageEmbed()
      .setTitle("Guess the Level!")
      .setDescription("Difficulty: Harder")
      .setColor("#ff7d36")
      .setImage(
        "https://cdn.discordapp.com/attachments/891672414361112616/892153203465027685/beautiful_vacations.PNG"
      )
      .setFooter(`Requested by ${message.author.username}`)
      .setTimestamp();
    console.log("Answer: Beautiful Vacations");
    message.channel.send({
      embeds: [LGEmbed1],
    });

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

When defining a filter, you can do this:

const filter = (m) => {
  if(m.author.id !== '123') return false;
  if(m.content.startsWith("Fever") return true;
}

Or, use the '&&' operator to pass in multiple arguments. For example:

const filter = (m) => m.content.startsWith('Fever') && m.author.id === '123'

I hope this helps you solve your problem. By the way, regarding your note, you don't need to apologize for asking a question. Everyone started off just like you are right now.

about 4 years ago · Juan Pablo Isaza Relatório

0

So as it turns out, my problem was extremely simple to solve. Basically, I needed to replace const with var, and boom, it worked.

Sample code below

case 0:
    const LGEmbed0 = new Discord.MessageEmbed()
      .setTitle("Guess the Level!")
      .setDescription("Difficulty: Medium")
      .setColor("#36ff69")
      .setImage(
        "https://media.discordapp.net/attachments/891672414361112616/892153208082923520/fever.PNG"
      )
      .setFooter(
        `Requested by ${message.author.username}`,
        `https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.webp`
      )
      .setTimestamp();
    console.log("Answer: Fever");
    message.channel.send({
      embeds: [LGEmbed0],
    });

    var filter = (m) => m.content.startsWith("Fever");

    message.channel
      .awaitMessages({ filter, max: 1, time: 10000, errors: ["time"] })
      .then((collected) => message.channel.send({ embeds: [cor] }))
      .catch((collected) => message.channel.send({ embeds: [time] }));

    break;

  case 1:
    const LGEmbed1 = new Discord.MessageEmbed()
      .setTitle("Guess the Level!")
      .setDescription("Difficulty: Harder")
      .setColor("#ff7d36")
      .setImage(
        "https://cdn.discordapp.com/attachments/891672414361112616/892153203465027685/beautiful_vacations.PNG"
      )
      .setFooter(`Requested by ${message.author.username}`)
      .setTimestamp();
    console.log("Answer: Beautiful Vacations");
    message.channel.send({
      embeds: [LGEmbed1],
    });

var filter = (m) => m.content.startsWith("Beautiful Vacations");

    message.channel
      .awaitMessages({ filter, max: 1, time: 10000, errors: ["time"] })
      .then((collected) => message.channel.send({ embeds: [cor] }))
      .catch((collected) => message.channel.send({ embeds: [time] }));

    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