Issues with bot connecting to mass channels

Hey there!

I created a chat bot for a single game and it’s blown up to the point where almost 2k channels use it… I was having no issues with the bot until I got to around 1950 channels on the bot. The bots channel list is a MySQL DB of names that have approved the bot to join their channel.

Around 1950+ channels, my bot started to just…break. It’ll receive a welcome, join the channels, and then just cylces…

Example of my bot’s output when over 1950 channels -> https://pastebin.com/fjJ4msFc

Bot’s code -> https://github.com/illogicalNetwork/LogicEFTBot ; twitch.py on_welcome is where I presume my issue is coming from?

Your bot is exceeded the “messages Twitch keeps in a queue to send you as your bot can’t keep up” queue and is being DC’ed

You need to spread the load of the chats/channels across multiple instances of the bot.

So for example

Instead of one bot on 2000 channels
You run 4 bots on 500 channels instead.

And/or adjust the load distrubution as needed so you don’t get DC’ed

You may also be exceeding the “join in x time” limit and getting DC’ed as a result, see Rate LImits https://dev.twitch.tv/docs/irc/guide#command--message-limits

Hmm, interesting. I have very little messages being sent, not even 1 per minute sometimes. Sometimes 4-5 minutes between messages.

My bot was setup to join 2000 channels and then sleep for 15 seconds and had issue.
I also tried 200 channels per 10 seconds to be safe and not exceed my limit (even though I’m verified and should have no issues joining more than that)

I tried changing my sleep time to 50 seconds, and, it’s been running for around an hour now without issue. This doesn’t make sense to me though because I’m not even connecting to 2000 channels, which is my limit… I have 1990 channels in the db and I’m not constantly JOINING them since I only welcome once?

The issue isn’t the messages your bot is sending, it’s the messages Twitch is trying to send to your bot on that single connection.

This is why you may experience inconsistent results, as at times of low chat activity you may be able to connect to lots of channels, but then at times of high chat activity you will experience issues if that single connection can’t keep up with the messages being sent by Twitch and the buffer builds up to the point where Twitch kills the connection.

The answer to this is to do as Barry suggested, and use multiple connections and to split the channels your bot is joining over those connections, as trying to run 2000 channels on a single connection is excessive.

Okay okay, starting to make sense now entirely. Working on implementing multiple connections already. However I am very confused still slightly.

What messages is Twitch trying to send to the bot? Is Twitch sending EVERY MESSAGE to the bot? The bot was in chats that were probably the most active over the last two hours and it’s been stable ever since I changed only my bot’s sleep time…

When you join a channel, Twitch sends you every chat message that is sent to that channel (other than your own messages, which Twitch doesn’t return to you) to your connection. The more channels your bot joins, the more traffic twitch sends on that connection, and eventually it will reach a point where your connection can’t keep up with handling that traffic and so Twitch kills the connection.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.