tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.55k stars 214 forks source link

object is not a function when trying to timeout #51

Closed jrdn91 closed 9 years ago

jrdn91 commented 9 years ago

When trying to use the timeout function I'm getting this error

[12:50pm] info: [#matax91] <matax91>: google.com
/Users/jordanriser/workspace/twitch_bot/routes/api/bot.js:85
      chatBot.timeout("matax91", "matax91", 1);
              ^
TypeError: object is not a function
    at client.<anonymous> (/Users/jordanriser/workspace/twitch_bot/routes/api/bot.js:85:15)
    at client.emit (events.js:118:17)
    at client.handleMessage (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/lib/client.js:468:30)
    at /Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/lib/client.js:602:18
    at Array.forEach (native)
    at client._onMessage (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/lib/client.js:600:11)
    at WebSocket.onMessage (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/WebSocket.js:414:14)
    at WebSocket.emit (events.js:110:17)
    at Receiver.ontext (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/WebSocket.js:797:10)
    at /Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:473:18
    at Receiver.applyExtensions (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:360:5)
    at /Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:462:14
    at Receiver.flush (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:336:3)
    at Receiver.opcodes.1.finish (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:478:12)
    at Receiver.expectHandler (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:453:31)
    at Receiver.add (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:91:24)
7 Sep 12:50:39 - [nodemon] app crashed - waiting for file changes before starting...

My code looks like this

chatBot.on('chat', function(channel, user, message, self){
  if(self){
    return true;
  }
  // Return if there is not a command
  if(!message.match(/!\w+/g)){
    // Moderate messages
    if(urlRegex.test(message)){
      chatBot.timeout(channel, user.username, 1);
      chatBot.say(channel, "Please do not post URL's in the chat.");
    }
    return true;
  }
...
});
AlcaDesign commented 9 years ago

Just as a suggestion, I would limit the command regex to the first character (perhaps after a trim) with the caret:

if(!message.trim().match(/^!\w+/g)){
jrdn91 commented 9 years ago

You're right on that one, the commands will always be the beginning of the string, thanks for the pointer. Now if only I can get this timeout to work.

Schmoopiie commented 9 years ago

Your chat event looks fine, can you try console.log(chatBot); to see if chatBot is defined ? It should return an object if it works.

Schmoopiie commented 9 years ago

Also, make sure you are using the latest version of tmi.js :smile:

systimotic commented 9 years ago

Hi there. Happy user of this repo here! I'm watching the repo and tracking what's going on through email. I noticed that there was something up with a notice for attempting to timeout the broadcaster and that seems to be the issue here. I do not recall whether that was fixed yet, but you might want to try it out with somebody else to see if is indeed the issue.

systimotic commented 9 years ago

https://github.com/Schmoopiie/tmi.js/issues/28#issuecomment-137814564 #28 Might be related, Twitch notice bad_timeout_broadcaster.

jrdn91 commented 9 years ago

^^ That may be the case here I didn't even think about that. I will test this out with another user and get back to this thread.

Schmoopiie commented 9 years ago

The notices are not causing an application to crash, it is only used to catch notices from Twitch (can be error messages or confirmation). For instance, if you use the timeout command on yourself, Twitch will respond with the msg-id bad_timeout_self which is You cannot timeout yourself. We will be using these notices and transform each and every command to support promises. We did it for .ban() already, see issue #44.

Edit: If a notice is not supported by the library, a message will tell you all the informations we need and you will be able to post it in issue #28

jrdn91 commented 9 years ago

I ran npm update for tmijs but I guess it didn't update, updating to 0.0.23 fixed the timeout not working.

Schmoopiie commented 9 years ago

Make sure the version of tmi.js in your package.json file has a caret (^), the caret will make npm update the module with the latest minor and latest patch version when you use ´´npm update´´