Contents

Joining a Chat Room

Reviews for Extensions, organizations, games, and chatbot verification are temporarily paused while we revise our processes. We are working to resume reviews as quickly as possible and will share updates with you shortly. Thank you for your patience and understanding.

Now that your bot has successfully authenticated with the Twitch IRC server, the next step is to join a chat room and begin sending and receiving messages.

To join one or more channels, use the JOIN message.

JOIN #<channel>,#<channel>

Here’s what the snippet of code might look like if you used this websocket package for Node.js.

client.on('connect', function(connection) {
    console.log('WebSocket Client Connected');
    
    connection.sendUTF('CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands');
    connection.sendUTF('PASS oauth:yfvzjqb705z12hrhy1zkwa9xt7v662');
    connection.sendUTF('NICK myusername');

    connection.sendUTF('JOIN #bar,#foo');
});

If the bot successfully joins the channel, the server replies with the JOIN, 353, and 366 messages. The text portion of the 353 message lists the users in the channel at the time you joined. The following example shows the reply message when the bar bot joined the #twitchdev and #foo channels.

:bar!bar@bar.tmi.twitch.tv JOIN #twitchdev
:bar.tmi.twitch.tv 353 bar = #twitchdev :bar
:bar.tmi.twitch.tv 366 bar #twitchdev :End of /NAMES list

:bar!bar@bar.tmi.twitch.tv JOIN #foo
:bar.tmi.twitch.tv 353 bar = #foo :bar
:bar.tmi.twitch.tv 366 bar #foo :End of /NAMES list

If the channel already has users joined to it, the reply may contain two 353 messages. The first shows the existing users in the chat room and the second shows the bot that joined.

:bar!bar@bar.tmi.twitch.tv JOIN #twitchdev
:bar.tmi.twitch.tv 353 bar = #twitchdev :xhipgamer blushyface mauerbac_bot moobot...
:bar.tmi.twitch.tv 353 bar = #twitchdev :bar
:bar.tmi.twitch.tv 366 bar #twitchdev :End of /NAMES list

If your bot requests the commands capability, the server’s reply also includes the USERSTATE and ROOMSTATE messages.

:bar!bar@bar.tmi.twitch.tv JOIN #twitchdev
:bar.tmi.twitch.tv 353 bar = #twitchdev :bar
:bar.tmi.twitch.tv 366 bar #twitchdev :End of /NAMES list
@badge-info=;badges=;color=;display-name=bar;emote-sets=0,300374282;mod=0;subscriber=0;user-type= :tmi.twitch.tv USERSTATE #twitchdev
@emote-only=0;followers-only=-1;r9k=0;rituals=0;room-id=141981764;slow=0;subs-only=0 :tmi.twitch.tv ROOMSTATE #twitchdev

:bar!bar@bar.tmi.twitch.tv JOIN #foo
:bar.tmi.twitch.tv 353 bar = #foo :bar
:bar.tmi.twitch.tv 366 bar #foo :End of /NAMES list
@badge-info=;badges=moderator/1;color=;display-name=bar;emote-sets=0,300374282;mod=1;subscriber=0;user-type=mod :tmi.twitch.tv USERSTATE #foo
@emote-only=0;followers-only=-1;r9k=0;rituals=0;room-id=713936733;slow=0;subs-only=0 :tmi.twitch.tv ROOMSTATE #foo

If you try to join a suspended or deleted channel, the bot receives a NOTICE message with the appropriate text. If your bot requests the tags capability, the message’s msg-id tag is set to msg_channel_suspended (for a list of msg-id IDs, see NOTICE Message IDs). If you try to join a nonexistent channel, Twitch quietly drops your JOIN message.

If you try to join channels in excess of your rate limit, Twitch drops your JOIN message. However, if you greatly exceed the rate limit, Twitch terminates the connection.

Next steps

After joining the chat room, the bot can start sending and receiving messages. See Sending and Receiving Chat Messages.