Estoy creando un juego similar a una trivia para un bot de Discord, pero tengo problemas para descubrir cómo puedo usar varios filtros ya que sigo recibiendo este error.
SyntaxError: el identificador 'filtro' ya se ha declarado
Aquí está mi código (solo los primeros 2 casos)
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], });Al definir un filtro, puede hacer esto:
const filter = (m) => { if(m.author.id !== '123') return false; if(m.content.startsWith("Fever") return true; }O utilice el operador '&&' para pasar varios argumentos. Por ejemplo:
const filter = (m) => m.content.startsWith('Fever') && m.author.id === '123'Espero que esto te ayude a resolver tu problema. Por cierto, con respecto a tu nota, no necesitas disculparte por hacer una pregunta. Todo el mundo empezó igual que tú ahora.
Entonces resultó que mi problema era extremadamente simple de resolver. Básicamente, necesitaba reemplazar const con var y boom, funcionó.
Ejemplo de código a continuación
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;