• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • Happy New Year everyone! A new version (1.0.0-beta.16) is out for Linux, fixing an issue that could lock the bot up when using it with TS3. Please visit the resources section or the main page (https://www.sinusbot.com) for the new package.

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