【发布时间】:2021-11-11 16:43:32
【问题描述】:
您好,我怎样才能将其更改为 30-50 秒之间的随机时间? 我不需要新代码或只是想编辑它
client.on('chat', function(channel, user, message, self) {
if (user.username == 'Cortex' && message === 'sar') {
test();
}
});
function test()
{
setInterval(function() {
var spamMessage = 'KEK ';
var toSpam = 'MingLee';
for (i = 0; i < 30; i++) {
spamMessage += toSpam + ' ';
}
client.say(channel, spamMessage)
}, 30000);
}
【问题讨论】:
-
这能回答你的问题吗? How to run setTimeout() with a random interval in each iteration in javascript?总之可以使用递归函数。
-
function sendMessage() { /* code */ window.setTimeout(sendMessage, randomNumber); }只需使用超时并一遍又一遍地调用函数
标签: javascript twitch-api