totalClients rip
I am slowly freaking out with the teamspeak server system, how can it be that there is the function "totalclients", but NOTHING is returned, I know that you can not do that and only use the values of teamspeak, but maybe you know where the problem is with me.
My problem: I want to see if a client is alone in the channel, and I want to do this as "efficiently" as possible, so I tried to use the following method:
My code:
try {
final Client musicCustomBot = Main.api.getClientByUId("MyClientUid");
final int channelID = musicCustomBot.getChannelId();
final String totalClients =
Main.api.getChannelInfo(channelID).get(ChannelProperty.TOTAL_CLIENTS);
System.out.println(totalClients + "total");
if (Integer.parseInt(totalClients) <= 1) Main.api.moveClient(musicCustomBot.getId(),
ChannelIdService.musikAfkChannel_ID);
} catch (Exception exception) {
System.out.println("Couldn't move team bots");
}
The Log Output on my Server:
2024-04-20T23:10:53.266343745Z total
2024-04-20T23:10:53.266395063Z Couldn't move team bots
My question: Am I currently doing something wrong or am I misinterpreting the problems?
Hi @qeinz
Yeah, this part of the serverquery interface is very counter-intuitive. The current number of clients in the channel is only included in the channellist response, but not in the channelinfo response. Usually, you'd assume that channelinfo would always deliver more information about the given channel than channellist, but this is unfortunately not the case with TS3...
As far as I can see, you essentially have 2 options, but neither of those is "minimal":
- Call
TS3Api#getChannelsto get a list of all channels, iterate over the list, pick out theChannelobject you're interested in, and callChannel#getTotalClientsorChannel#getTotalClientsFamilyon it (depending on whether you want to include clients in sub-channels in the count), or - Call
TS3Api#getClientsand manually count the number of clients whoseClient#getChannelIdis the channel you're interested in. This approach doesn't work if you also want to count clients in sub-channels.
Big thx to u <3 thx so much man!
it worked with the following code as u said:
public static void moveTeamBots() {
try {
final Client musicCustomBot = Main.api.getClientByUId("uid=");
final int channelID = musicCustomBot.getChannelId();
for (Channel channels : Main.api.getChannels()) {
if (channels.getId() == channelID) {
if (channels.getTotalClients() <= 1) Main.api.moveClient(musicCustomBot.getId(),
ChannelIdService.musikAfkChannel_ID);
}
}
} catch (Exception exception) {
System.out.println("Couldn't move team bots");
}
so wait is there a problem with spacer? like: [*cspacer1981245353541] if i move the bot in this channel the code doesnt move him out?
I can't really tell you too much without a server error message, but I have a hunch what might be going on:
The way these spacer channels are usually set up to prevent people from joining them is by raising the required join, subscribe, etc. powers up to a higher value. Now, if the channel subscribe power of the server query client you're using is lower than the required subscribe power for the spacer channel, you won't be able to subscribe to the channel, and thus your server query client will be unable to see any clients in such channels. In effect, the music bot will be invisible to you.
That's just my guess, though. If that's not it, please feel free to share any server errors / exceptions / whatever you're getting 😄
Ahh thats a wild guess, might be true, i will check it, thx for your massive help :D
u were right again my friend! it was the subscription power of the admin query which didnt had enougth, so i changed it, now its working :D thx <3
Awesome, great to hear that 😄
hey i unfortunately have the problem that sometimes it works and sometimes it doesn't, do you have a rough idea why that might be?
in some channels it works and in some it doesn't???
Sorry, no, nothing comes to mind. The only recommendation I can give you is to enable server query command logging and to inspect the logs when you notice that your application isn't working 🙂
Alright thx, how can i enable this ?
Call TS3Config#setEnableCommunicationsLogging(true) before passing the TS3Config object to the TS3Query constructor.
@qeinz If I'm following your intent and issue properly, you could do a check before moving to each channel, to ensure that it has the proper permissions. You could explicitly check if it's a spacer (those were mentioned earlier) if that actually is causing the issue. Also I definitetly recommend logging which channels cause the issue, if you're not.
thx guys for your help, will check it out asap!
so idk how and why, but this code is working right now:
public static void moveTeamBots() {
try {
final Client musicCustomBot = Main.api.getClientByUId("uid");
final int channelID = musicCustomBot.getChannelId();
if(channelID == ChannelIdService.musikAfkChannel_ID) return;
for (Channel channels : Main.api.getChannels()) {
if (channels.getId() == channelID && channels.getTotalClients() == 1) {
Main.api.moveClient(musicCustomBot.getId(), ChannelIdService.musikAfkChannel_ID);
}
}
} catch (Exception exception) {
System.out.println("exceptin; " + exception);
System.out.println("Couldn't move team bots");
}
}
I've added: if(channelID == ChannelIdService.musikAfkChannel_ID) return; xD