kritzware / twitch-bot

🤖 Easily create chat bots for Twitch.tv
https://www.npmjs.com/package/twitch-bot
MIT License
149 stars 36 forks source link

Multiple channels duplicates messages #30

Closed zfbx closed 6 years ago

zfbx commented 6 years ago

When I connect more than one channel the on message is repeated per the number of channels. To see what i mean https://imgur.com/a/fidvI All I'm doing is console logging the message and i'm connected to 3 channels

 twitch.on('message', msg => {
    console.log(`${msg.channel} ${msg.username}: ${msg.message}`);
}
zfbx commented 6 years ago

Oh and i'm using the npm version if that's important

kritzware commented 6 years ago

Hi @zfbTony, thanks for reporting this! I'm quite busy at the moment, but I'll take a look into this issue when I have some free time 👍

PBug90 commented 6 years ago

Its not a problem with the bot itself. The README gives the following example:


const TwitchBot = require('twitch-bot')

const Bot = new TwitchBot({
 ...
})

Bot.on('join', () => {
    console.log("join event!");
  Bot.on('message', chatter => {
    console.log(chatter.message);
  })
})

Bot.on('error', err => {
  console.log(err)
})

As we changed the code to handle multiple channels, the join event now fires for every successfully joined channel. This results in a new callback being registered each time, hence if you join the two channels it will fire twice, if you join three channels thrice and so on.

Solution: update the README.

@zfbTony make sure you adjust the code from the README to this:

const TwitchBot = require('twitch-bot')
const Bot = new TwitchBot({
 ...
})

Bot.on('join', () => {
    console.log("join event!");

})

Bot.on('message', chatter => {
console.log(chatter.message);
})

Bot.on('error', err => {
  console.log(err)
})

And you should be fine 😉

kritzware commented 6 years ago

Resolved with #31 👍