High network load

Do I understand correctly that for each new channel in my bot I have to create a new connection and send pass+nick+join there? It turns out that if I have 500 users, then I will have to create 500 separate connections to the server? This is very strange and looks like a place where there will be a huge loss of resources: both network and CPU time. Is it possible to work with multiple users in one connection (naturally on behalf of one bot)?

No, you can connect to as many channels as you want on a single connection. The only limit on channels per connection is your ability to keep up with the incoming message flood.

Assuming you want the same user to join all 500 channels.

Nightbot/Streamlabs/StreamElements dont have one instance of the bot for each channel they need to be in.

They’ll have an instance of the bot connect to, I don’t know say, 1000 channels per connection.

You do not need a new connection for each channel your bot needs to be in .

You only need a different connection/instance if you are also using a different bot username per channel.

You just need to join channeks in line with the stated join rate limits.

So if you bot uses the username bob

You can start bob and join

  • fred
  • sally
  • bob (bob’s own channel)
  • dave

and so on all on one connection/instance.

Great, but then I don’t understand how to implement it. I connect to the server, send there:
PASS oauth:token_first_channel + NICKNAME mybot. I am waiting for a response about successful authorization, and then I send JOIN #first_channel. The connection is established successfully and I get GLHF. Then I send PASS oauth:token_second_channel. I am waiting for a response from the server, and it just sends a packet with the FIN flag in response (communication is interrupted). On the website, the API did not find an exact way to connect to 2, 3, and so on channels that have a token.

You don’t do this…

You connect to chat as mybot with the password for mybot which is the oAuth token for mybot

You shouldn’t be using multiple passwords on the same connection.

So you are getting disconnected as you are trying to login as a second/different user on the same connection

So it should be

  • connect to chat
  • send the username for your bot
  • send the password for your bot (which is the oAuth token)
  • join channel(s)

When you join you can either do

JOIN #channel
JOIN #channel
JOIN #channel
JOIN #channel


JOIN #channel,#channel,#channel,#channel

(Each channel is different naturally), and you can do up to 100 channels in a single join request.

So in this example, you didn’t connect as mybot as the token overrides the username and you are now logged in as the user for token_first_channel

Broadly speaking you are doing it wrong.


A simple workflow:

  • My bot is barrycarlyonbot, which is a “real Twitch User”
  • I get a token for barrycarlyonbot which includes chat:read and and chat:edit
  • I connect to chat
  • I send the USER as barrycarlyonbot
  • I send the PASS of the oAuth token for barrycarlyonbot
  • I then JOIN all the channels I need to.

I will have oAuth tokens for streamers, but I don’t use those tokens when connecting to chat, just for reading subscriber data, for example, via the API.

So your chatbot only uses one token on the chat socket itself. And that token represents the user you want to send messages as, which generally will be your chatbot, not a streamer/broadcaster

1 Like

Thank you very much! Now I have a really correct understanding of how it works and have closed a lot of questions at once, not just this one!

The chosen solution is probably totally acceptable for you at this point, but it is not a complete solution and may (unlikely) cause problems in the future.

@BarryCarlyon is right that there is no reason to dedicate a connection for each channel, but if you find yourself in 1000 active channels on a single connection, the connection will drop.
It’s up to you how you divide up channels on different connections/instances since it depends entirely on activity and not a number of channels, but a simple channel limit will get you far (e.g., if you would join more than 50 channels, then join them on a new connection).

The connection is buffered and if the buffer would overflow, the connection will be dropped. This happens server-side and is irrespective of network connection: it would still happen even if you had an 800Gbps connection directly to the chat server.

This should be obvious from a networking standpoint (sure, if you already know how it works), but it’s also pretty easy to test if you don’t believe me. I’ll leave it as an exercise for the reader so Twitch doesn’t think I’m encouraging activities it might consider harmful (mass joining channels for no good reason).

Is that true? The documentation mentions “join attempts” without making clear whether that refers to JOIN messages or channels to join.

Can’t say I’ve taken the time to test the limits for sure

But I do often when I need chat samples, will get the first 100 live streams, concat the logins and fire that off to a join.

but I tend to only do 2 or 3 pages. (so 200 or 300 channels at most anyway).

Since “attempts” means if you try to join a banned channel, thats still “an attempt”. Generally I don’t get near rate limits so I’ve not tested the true practical limits of what works/doesn’t work. However when I’m also operating as a verified bot.

Minor note: I’m pretty sure it’s comma separated, not space separated:

JOIN #matwalsh #notmatwalsh
< :matwalsh!matwalsh@matwalsh.tmi.twitch.tv JOIN #matwalsh
:matwalsh.tmi.twitch.tv 353 matwalsh = #matwalsh :matwalsh
:matwalsh.tmi.twitch.tv 366 matwalsh #matwalsh :End of /NAMES list
@badge-info=subscriber/73;badges=staff/1,broadcaster/1,subscriber/0,twitchcon2017/1;color=#8A2BE2;display-name=matwalsh;emote-sets=0,17422,19194,21958,22338,22944,22945,33563,56135,58107,58108,58109,315734,429634,605142,1512303,300374282,301592777,301850800,472873131,477339272,488737509,537206155,610186276;mod=0;subscriber=1;user-type=staff :tmi.twitch.tv USERSTATE #matwalsh
@emote-only=1;followers-only=-1;r9k=0;room-id=122859157;slow=0;subs-only=1 :tmi.twitch.tv ROOMSTATE #matwalsh

> PART #matwalsh
< :matwalsh!matwalsh@matwalsh.tmi.twitch.tv PART #matwalsh

> JOIN #matwalsh,#notmatwalsh
< :matwalsh!matwalsh@matwalsh.tmi.twitch.tv JOIN #matwalsh
:matwalsh.tmi.twitch.tv 353 matwalsh = #matwalsh :matwalsh
:matwalsh.tmi.twitch.tv 366 matwalsh #matwalsh :End of /NAMES list

< @badge-info=subscriber/73;badges=staff/1,broadcaster/1,subscriber/0,twitchcon2017/1;color=#8A2BE2;display-name=matwalsh;emote-sets=0,17422,19194,21958,22338,22944,22945,33563,56135,58107,58108,58109,315734,429634,605142,1512303,300374282,301592777,301850800,472873131,477339272,488737509,537206155,610186276;mod=0;subscriber=1;user-type=staff :tmi.twitch.tv USERSTATE #matwalsh
@emote-only=1;followers-only=-1;r9k=0;room-id=122859157;slow=0;subs-only=1 :tmi.twitch.tv ROOMSTATE #matwalsh

< :matwalsh!matwalsh@matwalsh.tmi.twitch.tv JOIN #notmatwalsh
:matwalsh.tmi.twitch.tv 353 matwalsh = #notmatwalsh :matwalsh
:matwalsh.tmi.twitch.tv 366 matwalsh #notmatwalsh :End of /NAMES list
@badge-info=;badges=staff/1,twitchcon2017/1;color=#8A2BE2;display-name=matwalsh;emote-sets=0,17422,19194,21958,22338,22944,22945,33563,56135,58107,58108,58109,315734,429634,605142,1512303,300374282,301592777,301850800,472873131,477339272,488737509,537206155,610186276;mod=0;subscriber=0;user-type=staff :tmi.twitch.tv USERSTATE #notmatwalsh
@emote-only=0;followers-only=-1;r9k=0;room-id=181789873;slow=0;subs-only=0 :tmi.twitch.tv ROOMSTATE #notmatwalsh
1 Like


My derp :smiley: didn’t check my stuff to check that it was :smiley: so yeah it’s comma… goes to edit earlier post

Yeah, comma, forgot since I just use my little lib/parser :smiley:

1 Like



With a regular account, I tried joining 51 channels (assuming IRC’s 510 byte limit applies) with a single JOIN command and it only joined the first 20.

As in it follows the rate limits.

Which yes I should of referenced in my initial response. (But I didn’t consider since I’m usually operating as a verified bot anyway and generally I don’t need to mass join too often for my use cases)


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