Hi. I was wondering how to send a message whenever someone said a specific phrase (sortof like what waehofen does... lol) I thought: Code (text): ({ afterChannelMessage: function(message, channel, html) { if (message == "abc") { client.network().sendChanMessage(channel, "def"); } } }); would work, but it doesn't seem to. Any idea what I'm doing wrong? :c
Because the message isn't "abc", it's "Playername: abc". Message includes the player's name as well, you'll have to remove that part.
If I'd say 'There are three great things on this planet: life, water and me', then message.split(":")[1] would return just ' There are three great things on this planet'. Better would it be to use: Code (text): variable = message.split(":"); variable.splice(0,1); variable = variable.join(":"); where .splice(0,1) removes the first item from an array, and .join(":") adds the items in the array back together with a : between them.
You're wrong. Arrays start at 0, so it would return "life, water and me". @SongSing: if (message.indexOf(':') >= 0) { message = message.substr(message.indexOf(':') + 2); }
I said "If I'd say ...", therefore, the variable message would be Wanderer M: There are three great things on this planet: life, water and me. That means message.split(":")[1] would return ' There are three great things on this planet'.
I don't know if this thread still needs help but. This is what I use, but I have it under beforeChannelMessage, but should work exactly the same in afterChannelMessage unless ya need to sys.stopEvent() for something: Code (JavaScript): var vUserSentName = message.substring(0, message.indexOf(':')); var vUserSentMessage = message.substr(message.indexOf(':') + 2); Now ya can simply: Code (JavaScript): if (vUserSentMessage === "trigger") { client.network().sendChanMessage(channel, "Hello."); }