Skip to content

Connecting

Julien edited this page Mar 17, 2020 · 3 revisions

You have two options to connect to Twitch IRC, using a regular Twitch account or anonymously. Most times, you would want to use a user account as it allows you to participate in chat and even take moderator actions, granted you have sufficient permissions in a channel. However, sometimes all we want to do is read the chat of one or multiple channels. This is possible by connecting anonymously.

Regular connection

To establish a regular connection, you use the twirc_connect() function:

int twirc_connect(twirc_state_t *s, const char *host, const char *port, const char *nick, const char *pass);

Note that the pass is not the regular password of the Twitch account you are using. Instead, you need to use an OAuth-token. To acquire such a token, visit the Twitch OAuth Token generator.

Connecting this way, both the welcome as well as the globaluserstate events should fire soon after you're authenticated.

Anonymous connection

To establish a connection that does not require any user credentials, use twirc_connect_anon():

int twirc_connect_anon(twirc_state_t *s, const char *host, const char *port);

If you use this approach, your username will be justinfan<random_number>, where random_number will be a random integer. You can query this information later on using twirc_get_login(), which will return a struct with a nick member.

Note that when connecting anonymously, no globaluserstate event will fire. Instead, keep an eye on the welcome event in order to know when it is safe to join channels.

Host and Port

At the time of writing, the following should work:

  • Host: irc.chat.twitch.tv
  • Port: 6667
Clone this wiki locally