kritzware/twitch-bot

Multiple channels duplicates messages

Closed this issue ยท 4 comments

zfbx commented

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

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

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 ๐Ÿ‘

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 ๐Ÿ˜‰

Resolved with #31 ๐Ÿ‘