const { TeamSpeak } = require("ts3-nodejs-library")
const groupToAssign = 7;
const teamspeak = new TeamSpeak({
host: "127.0.0.1",
queryport: 10011,
password: '6ohDFLjr',
username: 'serveradmin',
serverport: 9987,
})
teamspeak.on("ready", () => {
Promise.all([
teamspeak.registerEvent("server"),
teamspeak.registerEvent("channel", 0),
teamspeak.registerEvent("textserver"),
teamspeak.registerEvent("textchannel"),
teamspeak.registerEvent("textprivate")
])
})
teamspeak.on("clientmoved", info => {
switch (info.channel.flagPermanent) {
case 1:
if(!info.client.servergroups.includes(groupToAssign) && teamspeak.getClientByDBID(info.client.databaseId).then(groups => {groups.getGroups().contains(groupToAssign)}))
teamspeak.clientAddServerGroup(info.client.databaseId,groupToAssign);
break;
default:
if(info.client.servergroups.includes(groupToAssign)){
teamspeak.clientDelServerGroup(info.client.databaseId,groupToAssign);
}
break;
}
});
teamspeak.on("clientmoved", async info => {
// wrap it all in try catch i dont know :D
switch (info.channel.flagPermanent) {
case 1:
const is_client_contain_group = info.client.servergroups.includes(groupToAssign)
const is_server_have_group = await teamspeak.getClientByDBID(info.client.databaseId).then(groups => groups.getGroups().contains(groupToAssign))// .catch(err=> console.log("err on [server_have_group]")) kind of to debug on possible errors
if(!is_client_contain_group && server_have_group ))
await teamspeak.clientAddServerGroup(info.client.databaseId, groupToAssign);
break;
default:
if(info.client.servergroups.includes(groupToAssign)){
await teamspeak.clientDelServerGroup(info.client.databaseId,groupToAssign);
}
break;
}
});
You want this bot to put it on danger community server ? haahaHi..
I Need Bot Give every body in temporary channel servergroup if he go to permanent bot revoke this server group
Thank you for watching into code, yes my bad for not reasearching promise in full. Rn it doenst return bool, returns pending like u said, but still this condition passes so its kinda good -.-' .@kalle
JavaScript:teamspeak.on("clientmoved", async info => { // wrap it all in try catch i dont know :D switch (info.channel.flagPermanent) { case 1: const is_client_contain_group = info.client.servergroups.includes(groupToAssign) const is_server_have_group = await teamspeak.getClientByDBID(info.client.databaseId).then(groups => groups.getGroups().contains(groupToAssign))// .catch(err=> console.log("err on [server_have_group]")) kind of to debug on possible errors if(!is_client_contain_group && server_have_group )) await teamspeak.clientAddServerGroup(info.client.databaseId, groupToAssign); break; default: if(info.client.servergroups.includes(groupToAssign)){ await teamspeak.clientDelServerGroup(info.client.databaseId,groupToAssign); } break; } });
Would be bettet to write event handler like that (might not be 100% working cause i writing it while chilling).
Keep in mind lib is promise based. Using await will be better solution in 99.9% cases.
`teamspeak.getClientByDBID(info.client.databaseId).then(groups...` wil return Promise<pending> value (not boolean).
Why you choose Array.prototype.includes and Array.prototype.contains instead one of this ?
Also would be cool with usage if instead switch with one value (less code, and if works faster )
false
undefined
NaN
null
0
''