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

Why is this code snippet not working anymore?

Status
Not open for further replies.

xDefcon

Well-Known Member
Contributor
I need to send a private message to everyone, as i can't find a documentation about it, i saw a similar script by raphraph. What is wrong with this snippet, is this a bug of lastest sinusbot beta? (i think in old version worked).

When i run it, sinus says "Can't chatPrivate of undefined" or similar thing (i don't remember that atm)

Code:
  var clients = getClients();
            for (var j = 0; j < clients.length; j++) {
                var client = clients[j];
                chatPrivate(client.id, "hello");
            }


   function getClients() {
        var channel, channels, clients = [];
        channels = getChannels();

            for(var i = 0; i < channels.length; i++){
                channel = channels[i];
                clients.push(channel.clients);
            }
            return clients;
    };
 

mxschmitt

Moderator
Staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
do you have it like that?
Code:
 sinusbot.on('chat', function(ev) {
// your code
}
 

mxschmitt

Moderator
Staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
You need a ev. in front of the clientId
like that:
ev.clientId
 

xDefcon

Well-Known Member
Contributor
do you have it like that?
...
Code:
  var clients = getClients();
            for (var j = 0; j < clients.length; j++) {
                var client = clients[j];
                chatPrivate(client.id, "hello");
            }
it's inside a function, and that function is runned every X secs, so is not called after an event (like chat).
 

mxschmitt

Moderator
Staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
try a ev. In front of that variable ;)
 

Xuxe

Containerholic
Staff member
is awesome!
V.I.P.
Contributor
Insider
Code:
   function getClients() {
       var channel;
       var channels, clients = [];
       channels = sinusbot.getChannels();

       for (var i = 0; i < channels.length; i++) {
           channel = channels[i];
           for (var x = 0; x < channel.clients.length; x++) {
               clients.push(channel.clients[x]);
           }
       }
           return clients;
       };

       var clients = getClients();
       for (var j = 0; j < clients.length; j++) {
           var client = clients[j];
           sinusbot.chatPrivate(client.id, "hello");
       }

Should work, not tested.

About the undefined message: https://forum.sinusbot.com/threads/upcoming-changes-for-the-scripting-engine.1113/ ^^
 
Last edited:

xDefcon

Well-Known Member
Contributor
@Xuxe yes, it works. So basically
Code:
channel.clients
is an multidimensional-array of clients with client.id, name etc, right?
 

Xuxe

Containerholic
Staff member
is awesome!
V.I.P.
Contributor
Insider
is an multidimensional-array of clients with client.id, name etc, right?

It is a normal array of client objects :) But its not multidimensional. Multidimensional would be
Code:
example[1][1]
 

Raphraph

Donor
is awesome!
Contributor
Insider
@Xuxe any documentation or method to know that at the moment? :p
uh right
btw, ty for the help
So, to start, I'm sorry I did not have the time to reply here :D Next time, just write @Raphraph somewhere, if you have some questions about parts of my scripts ;)

And, coming back to quour question, in the web-interface, you should have a link at the top named "Help". Then on the left side a link called something like " Scripting". There you should find a documentation about scripting :)
(I'm not quite sure about the namds, because I cannot access an interface currently :D )
 
Status
Not open for further replies.
Top