• 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 Client's group IDs into a string

Status
Not open for further replies.

kanalumaddela

Insider
Insider
*Issue resolved and code is updated for reference*

So .getServerGroups() works and retrieves an array of a client's group. Reading the array works fine also, but when reading the array in a for loop it doesn't work.

Here's an example snippet of code. I felt like commenting for some reason. Basically what I'm trying to do is grab the group IDs a user has and place it into a string where each ID is separated by a comma. Then when it's used later it'll be turned into an array.
PHP:
// saves the array of a client's groups to a variable
var clientgroups = ev.client.getServerGroups();
// tells the client the id of the first group in the array
ev.client.chat('1st group in array: ' + clientgroups[0].ID() );
// tells how many groups a user has
ev.client.chat('You have ' + clientgroups.length + ' groups.');

// variable which will be used to save all the group IDs a client has
var clientgroupidlist = '';

// loop to add all the IDs into a string
for (i = 0; i < clientgroups.length; i++) {
    var tempid = clientgroups[i].ID();
    // creates a string of the IDs separated by a comma
    clientgroupidlist += tempid + ',';
}

// tells the client all the group IDs they have
ev.client.chat('Your group ids are: ' + clientgroupidlist);

// creates an array of just the IDs
var clientgroupidarray = clientgroupidlist.split(',');

Now the part at which I said it fails, here's what the bot shows in console
Code:
2016/12/31 19:43:35 3fe8f87f 1994ee9e INFO   PRIVATE-CHAT [Tunes] 1st group in array: 33
2016/12/31 19:43:35 3fe8f87f 1994ee9e INFO   PRIVATE-CHAT [Tunes] You have 5 groups.
2016/12/31 19:43:35 3fe8f87f 1994ee9e WARN   Error in script: TypeError: Cannot access member 'ID' of undefined
 
Last edited:

flyth

is reticulating splines
Staff member
Developer
Contributor
Looks really weird, will need time to investigate. What works though, is .forEach(...) - please use that as a workaround for the time being.
 
Status
Not open for further replies.
Top