I
I
Ivan Wagner2020-01-10 21:37:06
JavaScript
Ivan Wagner, 2020-01-10 21:37:06

How to randomize between setInterval?

Hello! There is a code like this:

const fs = require('fs');

client.on('message', function (message) {
    if (message.content !== "$loop") return;

    fs.readFile('keys.txt', { encoding: 'utf8'}, (err, data) => {
        if (err) throw err;
        const linesOfFile = data.toString().split("\n");

        setInterval(() => {
            message.channel.send(linesOfFile.shift());
        }, 10000);
    });

    fs.readFile('keys2.txt', { encoding: 'utf8' }, (err, data) => {
        if (err) throw err;
        const linesOfFile = data.toString().split("\n");

        setInterval(() => {
            message.channel.send(linesOfFile.shift());
        }, 7000);
    });
});

root - a call from the text editor of phrases that will be thrown once an hour. root2 - analogue, which should, between 13:00 and 14:00, for example, drop a number in a random interval. Something like from 13:10 to 13:50.
I can’t understand, my head no longer boils at these intervals. This is shitty code, sorry. I don’t know how otherwise .. It
’s not difficult for anyone, please help me to properly arrange all this so that it works. Now

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question