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

Solved help with coding script

Status
Not open for further replies.

Erik444

Member
how to make !command [optional argument]
i have this
Code:
if(ev.msg == '!abrazo' && ' ')
                    {
                        var msg = config.message;
                       
                        msg = msg.replace('%n', ev.clientNick);
                        msg = msg.replace('%r', ev.msg);   
                        chatChannel(msg);       
                    }else
                    {
                        chatChannel(errorMensaje);   
                    }

srry.. im new on this.. :c

i cant make " !abrazo nick "
 

CubE135

Donor
is awesome!
Contributor
If i am understanding you correctly, you could just use startsWith or slice instead of doing
Code:
ev.msg == '!abrazo'
 

Erik444

Member
Code:
        var errorMensaje = config.errorMensaje;
                    var msg = config.message;
                    if(ev.msg == '!abrazo')
                    {
                        chatChannel(errorMensaje);   
                           
                    }else if(ev.msg == '!abrazo' ) //here are the arguments (the nick)
                    {
                        msg = msg.replace('%n', ev.clientNick);
                        msg = msg.replace('%r', ev.msg); 
                        //msg = msg.replace(%d, here are the arguments (the nick))
                        chatChannel(msg);   
                    }
 

CubE135

Donor
is awesome!
Contributor
Ok, try this:
Code:
var prefix = "!";
var words = [];
if (msg.startsWith(prefix)){
    msg = msg.slice(prefix.length);
    words = str.split(" ");
   
    if (words[0] == 'abrazo') {
        if (words[1]){
            chatChannel(words[1]+' hugged '+words[1]);
        }
    }
}
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
i have this error : TypeError: 'startsWith' is not a function at Abrazo.js
As the sinusbot still uses ECMAScript 5 this is not available by default, add the following code at the beginning to make it work:
Code:
if (!String.prototype.startsWith) {
    String.prototype.startsWith = function(searchString, position){
      return this.substr(position || 0, searchString.length) === searchString;
  };
}
 
Status
Not open for further replies.
Top