client.on('message', message => {
if (message.author.bot) return;
if (message.content.startsWith('!french')) {
let channel = client.channels.cache.get('766344174379204622');
let responses = ['(。··)_且 would you like a fresh french press sir?(。··)_且', '(。··)_且 would you like some milk cubes sir?(。··)_且', '(。··)_且 how about some local honey with that sir?(。··)_且', '(。··)_且 now for the perfect cup of coffee sir...(。··)_且'];
let i = 0;
setInterval(function() {
if(i === responses.length-1) clearInterval(this);
channel.send(responses[i]);
i++;
}, 60000);
}
});
This will send each response with a 60 second delay. You can change the time to whatever you prefer. Ok, so what have I done? At first I defined the channel, where I would like to have the responses in (it is the channel ID from your question right now). Then I defined an array with your responses inside it. Then I created i
with the value 0, because an array always starts at index 0. Then I used setInterval, which takes in a function and a duration in ms. Inside the function it checks if i
is equal to the last index of responses
. responses.length
is the length of the array, in this case it has a length of 4. But as we want to check if i
is equal to the last index we have to use responses.lenght-1
, this will be 3. So if i
is equal to 3, the interval gets cleared and the responses don't get send anymore. Otherwise if i
is not equal to 3, it will send the responses at the index i
to your channel and count up i
by one (i++
).
For example:
The first run would be: i == 0
, so it sends the first response (responses[0]
) to your channel. i
gets count up and is now 1. It will wait 60 seconds and will repeat the same procedure.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…