Entonces, tengo esta parte del código de un bot de prueba hecho con discord.js .
Configuré el filtro de colector máximo: 1, pero cuando 2 o más usuarios responden con la respuesta correcta en el mismo SEGUNDO, ambos obtienen los puntos y debe ser solo un usuario, no 2 o más.
Ejemplo de que esto ocurra:
El código:
const filter = (m) => !m.author.bot && m.content.toLowerCase() == current.answer.toLowerCase(); const collector = message.channel.createMessageCollector({ filter, max: 1, time: 45000 }); collector.on('collect', async m => { if (stop == true) return; if (m.content == null || current.answer == null || m.content.toLowerCase() != current.answer.toLowerCase()) return; collector.stop(); remaining = Date.now() - time; points = remaining <= 5000 ? 10 : (remaining <= 15000 ? 8 : remaining <= 25000 ? 6 :(remaining < 35000 ? 4 : 2)); message.channel.send(`Correct! The answer is **${current.answer}**\n**${m.author.tag}**! You got **${points}** points!`).catch((err) => {console.log(err)}); if (fs.existsSync(`./system/users/${m.author.id}.json`)) { data = JSON.parse(fs.readFileSync(`./system/users/${m.author.id}.json`)); data.total += points; data.current += points; data.tag = m.author.tag; fs.writeFileSync(`./system/users/${m.author.id}.json`, JSON.stringify(data, null, 4)); } else { fs.writeFileSync(`./system/users/${m.author.id}.json`, JSON.stringify({ "id": m.author.id, "tag": m.author.tag, "current": points, "total": points }, null, 4)); } await wait(5000); return(md('NEXT')); });Como no proporcionó el código donde se define el mensaje original, es difícil encontrar una respuesta exacta al problema.
Un método sería comparar el ID del autor con el mensaje original, así:
const filter = (m) => m.author.id === <Message>.author.idEjemplo completo:
const filter = (m) => !m.author.bot && m.content.toLowerCase() == current.answer.toLowerCase() && m.author.id === <Message>.author.id; Reemplazando <Message> con el objeto de mensaje original.