• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN Get number of clients in a channel?

Status
Not open for further replies.

flyth

is reticulating splines
Staff member
Developer
Contributor
You can iterate through getChannels, find the channel and then use the clients-array to count.
 

sync667

Insider
Insider
Code:
/*
         Function return array of all clients connected to server or channel
         */
        function getClients(channelId) {
            var channel, channels, clients = [];
            channels = getChannels();
            if (typeof channelId == 'undefined') {
                for(var i = 0; i < channels.length; i++){
                    channel = channels[i];
                    clients.push(channel.clients);
                }
                return clients;
            } else {
                for(var i = 0; i < channels.length; i++){
                    channel = channels[i];
                    if(channel.id == channelId){
                        return channel.clients;
                        break;
                    }
                }
            }
            return [];
        };

Should help, then just use clients.lenght to get int.
 
Status
Not open for further replies.
Top