Answer the question
In order to leave comments, you need to log in
How to make Discord JS script re-execute?
To automatically re-execute the script, I use setInterval, because for some reason, process.exit() doesn't want to work properly (if it were to exit the script, then I already have a wait code that sleeps for the specified time). But I want to make the code run immediately, and only then the setInterval countdown starts. Or you need to find out why the output of the script does not work properly. It's just that if an error occurs and the script restarts, then you have to wait another time to execute setInterval, but I don't need it.
There is a code
connection.query(`.......................`, async function(err, response) {
if (response.length > 0) {
for (let i = 0; i < response.length; i++) {
///// Часть кода
connection.query("INSERT INTO ................");
console.log("Created daily record for " + userdata.username);
console.log( i+1 + "/" + response.length);
}
console.log('Следующий запуск через 24 часа');
//process.exit();
}
})
Answer the question
In order to leave comments, you need to log in
Are you using process.exit()
to stop script execution? But he does not want to work "normally" and stops Node itself.
And so, put your script in a function and restart the function at the required intervals. If I understand you correctly...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question