• 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 Need help with replace()

Status
Not open for further replies.

SlamaFR

Member
Hi !

I'm currently developping a support script and I need to replace some string like "%p" or "%n", but I can't simply do :
Code:
client.chat(config.messageToUser.replace('%p', config.prefix).replace('%n', client.nick));

It tells me :
Code:
Error in script: RangeError: expected 0 argument(s); got 3

Any idea ? :p
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Sure that this Line is the Reason of the Error?
Maybe you want to show us a bit more of your Script or your Error Log, would be for sure helpful
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Check if you really got a string in your config :p
 

SlamaFR

Member
=> tried with client.nick()

Still, the error confuses me as well :/
YEP ! That was the problem..

Do you know a method to send a message to all users that are in a servergroup ? I mean, you give "45,23,64,etc' in the config and the bot send a message to all users in these servergroup..
 

SimoBot

Insider
Insider
YEP ! That was the problem..

Do you know a method to send a message to all users that are in a servergroup ? I mean, you give "45,23,64,etc' in the config and the bot send a message to all users in these servergroup..

https://www.sinusbot.com/docs/scripting/#Backend.getClients

there is an example. You have to check the server group of the user before sending the message with client.getServerGroups() that gives you an array with a servergroup object (made up with name and id). Run through the servergroup.id and check the servergroup id.
 

SlamaFR

Member
I tried this but doesn't work :/

Code:
function notifyStaff(client, channel) {
        backend.getClients().forEach(function (c) {
            c.getServerGroups().forEach(function (g) {
                engine.log(g.ID());
                if (staff.indexOf(g.ID()) > 0) {
                    engine.log('sending to '+c.name());
                    /*
                    switch(config.messageToStaffMethod) {
                        case "0":
                            client.chat(config.messageToStaff.replace('%p', config.prefix).replace('%n', client.nick()).replace('%c', channel.name()));
                            break;
                        case "1":
                            client.chat(config.messageToStaff.replace('%p', config.prefix).replace('%n', client.nick()).replace('%c', channel.name()));
                            engine.log('Poke function unavailable');
                            break;
                    }
                    */
                }
            });
        });
    }
 

SlamaFR

Member
Well, actually the code works and log me the ID of each group.

In my config, I have a string field in my config which basically get the groups corresponding to staff, e.g. "23,24,35". And I just want to check all the groups of all the clients to determine which clients must be notified.
 
Status
Not open for further replies.
Top