我正在为Sinusbot(一个Bot for TeamSpeak)编写脚本,并且想编写一个脚本来检查用户是否已加入该频道。JavaScript setTimeout Sinusbot
问题在这里:我希望脚本在用户之后执行某些操作是在该通道中10秒钟!
我试过setTimeout
但它没有奏效。
我做错了什么?
if (ev.newChannel == channel_10m){
//if someone joins channel_10m
//wait 10 seconds
setTimeout(function(){
if (ev.newChannel == channel_10m){
//check if user is in channel_10m
//do somethink
}
}, 10000);
}
Sinusbot API:https://www.sinusbot.com/scripts/scripting3.html
编辑:
var timeout;
sinusbot.on('clientMove', function(ev) {
if (ev.newChannel == channel_10m) {
timeout = setTimeout(() => {
sinusbot.chatPrivate(ev.clientId, msg1);
}, 10000);
}
}
sinusbot.on('clientMove', function(ev) {
if (timeout) {
clearTimeout(timeout);
sinusbot.chatPrivate(ev.clientId, msg2);
}
}
EDIT2:
我懂了:
if (ev.newChannel == achannel_entrance){
setTimeout(function(){
if ((sinusbot.getChannel(1267)['clients'][0]['id'] && ev.newChannel) == (sinusbot.getChannel(1267)['clients'][0]['id'] && achannel_entrance)){
sinusbot.chatPrivate(ev.clientId, msg0);
sinusbot.move(ev.clientId, bchannel_support);
}
}, 300000);
}
你的代码看起来不错,setTimeout应该工作。看看javascript控制台的错误。使用javascript调试器查看程序中是否达到了setTimeout。 –
没有“错误”。我只是需要一些思考来检查用户是否仍然在该频道中10秒后。 – ZarneXxX
你确定你的程序正在进入if块吗? 'ev.newChannel == channel_10m'是真的吗? – josemigallas