0
I am programming a bot for Discord that asks questions and checks if they are right, but the doubt that this taking nn is with the lib discordjs itself but with the language itself!! And the following one: He asks the question but to ask the next question and I need this first question to be answered first! To know the answer I use the reactions which is a feature of Discord, and then I get the number of votes on that question and release only when the variable is changed To monitor this variable I need to use a setInterval structure and when it is different from 1 it executes the code! But the loop continues as I get the questions from an array! How can this loop that extracts the questions from the array continue after this variable is changed??
here goes the crucial third of the code
for (const i in PerguntasEmbaralhadas) {
var pergunta = PerguntasEmbaralhadas[i]
var exec = true
var questao = await msg.channel.send({ embed: pergunta });
const Alternativas = { 1: '', 2: '', 3: '', 4: '' }
for (const a in Alternativas) {
await questao.react(Alternativas[a])
}
}
const revisor = await setInterval(async () => {
var countAnwser = await questao.reactions.cache.map(reaction => reaction.count)
for (const i in countAnwser) {
if (countAnwser[i] != 1) {
await msg.reply(`Sua resposta foi a alternativa ${i + 1}`)
clearInterval(revisor)
semaforo = true
} else {
bsemaforo = false
}
}
}, 1000)
}
thank you so much
place the piece of code inside a
while
and control with a variable, for examplevar continuar = true; while (continuar) { ...aqui vai o codigo, quando a pergunta for repondida, faça continuar = false }
– Ricardo Pontual
All post code or subtitle for while?
– william
put in while the code asking first question, so it will remain in that while until the question is answered
– Ricardo Pontual
As you are working with asynchronous reactions, this can be a little more complicated than you might imagine. Also, utilize a
setInterval
is far from ideal in this case. Perhaps it is the case that you search for events and perhaps about reactive programming.– Luiz Felipe
Is there another simple method, where I can monitor these variables and perform some function as soon as it changes??
– william