• 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 AddToServerGroup

DrWarpMan

Well-Known Member
Contributor
Insider
So, I am making a script, but.. how can I add server group to client, via name? And not a number? Or it is possible to add it via name, but I am writing it wrongly?

"addToServerGroup(group: (ServerGroup | string | number))"

It says string or number, so.. idk

ev.client.addToServerGroup('test');

?
 
You can use a ServerGroup object, or the ID of the server group.
 
You either pass a servergroup object or the ID as a string or number, passing the name is not supported.
If you want to add it via name you first have to find it in engine.getServerGroups().

For example like this (not tested, might have typos):
JavaScript:
var backend = require("backend")
var group = getServerGroupByName("foobar")

// in some event:
ev.client.addToServerGroup(group)
// ...

function getServerGroupByName(name) {
    var groups = backend.getServerGroups()
  
    for (i in groups) {
        var sg = groups[i]
        if (sg.name() == name) {
            return sg
        }
    }
    return null
}
 
Last edited:
Is something wrong with this?

Code:
    var engine = require('engine');
    var backend = require('backend');
    var event = require('event');
   
    // listen for chat event
    event.on('chat', function (ev) {
       
        if(ev.text == "Hulk")
        {
            var skupina = getServerGroupByName(ev.text);
            ev.client.addToServerGroup(skupina);
            return;
        }
       
    });
   
    function getServerGroupByName(name) {
        var groups = engine.getServerGroups()
       
        for (i in groups) {
            var sg = groups[i]
            if (sg.name() == name) {
                return sg
            }
        }
        return null
    }
 
Yeah I made a typo
engine => backend
 
THANKS, WORKS <3
Btw. in the function, is there already a function that checks if that group does even exists? I mean, what happens if it doesnt exist? No error?
 
Btw. in the function, is there already a function that checks if that group does even exists? I mean, what happens if it doesnt exist? No error?
If it doesn't exist the function returns null.

JavaScript:
var group = getServerGroupByName("somethingthatdoesnotexist")

if (!group) {
    // does not exist
} else {
    // does exist
}
 
Back
Top Bottom