Answer the question
In order to leave comments, you need to log in
How can I make it so that when I use this command I cannot use it until the time set on the timer has passed?
I used this timer when writing a command in a discord bot, but I ran into a problem, since I planned that the command could be used once every half an hour, and it is used an unlimited number of times, it just runs in half an hour, what should I do?
Thank you all in advance
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
let iteration = 0;
let handleOffset = 60000 * 30;
(async () => {
while (iteration < handleOffset) {
iteration = iteration + 1000;
console.log('Осталось: ' + (handleOffset - iteration) + 'сек');
await sleep(1000);
}
})();
setTimeout(() => console.log('Хоба!'), handleOffset);
Answer the question
In order to leave comments, you need to log in
there is an answer in your question:
while (iteration < handleOffset) { . . .
just make an if-statement with a check for iteration and handleOffset:
if (iteration < handleOffset) {
// действие, которое происходит, пока iteration меньше handleOffset
} else {
// действие, которое происходит при остановке таймера
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question