tmijs / tmi.js

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

Listener on each channel #271

Closed Azayzel closed 6 years ago

Azayzel commented 6 years ago

Actual behaviour: Can’t seem to add an event listener for each channel I’m connecting to.

Expected behaviour:

If I connect to say, 100 channels, I want to listen for a channel join event of some sort or a message that came in on each channel so I can handle those accordingly.

Error log:

Insert your error log here

Server configuration

billygerhard commented 6 years ago

The listeners are global. If you have different logic, you need to filter that in the function.

client.on("chat", function (channel, userstate, message, self) {
  if (channel==='#user1'){
    user1ListenerFunction(channel, userstate, message, self)
  }
  else if (channel==='#user2'){
    user2ListenerFunction(channel, userstate, message, self)
  }
});

You can use a switch/case as well if you like, but that is the basic idea if you want to have 1 listener for multiple channels. Have 1 listener, and then forward those to channel specific functions.