gpt4 book ai didi

JavaScript setTimeout Sinusbot

转载 作者:行者123 更新时间:2023-12-03 04:55:48 24 4
gpt4 key购买 nike

我正在为 Sinusbot(TeamSpeak 的 Bot)编写脚本,并且想要编写一个脚本来检查用户是否已加入 channel 。

这里的问题:我希望脚本在用户进入该 channel 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);
}
}

编辑2:

我明白了:

        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);
}

最佳答案

如果您的问题是想检查用户是否仍然连接,您可以尝试以下操作:

var timeout;

sinusbot.on("connect", ev => {
if (ev.newChannel == channel_10m) {
timeout = setTimeout(() => {
doSomething();
}, 10000);
}
}

sinusbot.on("disconnect", ev => {
if (timeout) {
clearTimeout(timeout);
}
}

编辑:我认为您现在所做的是取消超时,无论客户端移入或移出。您应该跟踪不同的客户,让我们尝试一下:

// Dictionary for <clientId, timeout>
const timeouts = [];

// Event triggers when a client goes online or offline
// If client disconnects channel will be 0
sinusbot.on('clientMove', function(ev) {
const clientId = ev.clientId;

if (ev.newChannel == channel_10m) {
timeouts[clientId] = setTimeout(() => {
sinusbot.chatPrivate(clientId, msg1);
}, 10000);

} else if (ev.newChannel == 0 && timeouts[clientId]) {
clearTimeout(timeouts[clientId]);
sinusbot.chatPrivate(clientId, msg2);
}
}

关于JavaScript setTimeout Sinusbot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42432982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com