Skip to main content

Chat

Twitch offers an IRC interface to our chat functionality. This allows you to, for instance:

  • Develop bots for your channel.
  • Connect to a channel’s chat with an IRC client instead of using the Web interface.

The library follows the official rate-limits, and will automatically space out your calls to comply with these limits. These limits include joining/leaving channels, sending messages, sending whispers, and opening new connections.

Methods

Use as part of Twitch4J

To use Twitch Chat and events from chat, you need to specify withEnableChat when building the Twitch4J Instance, as shown below:

// chat credential
OAuth2Credential credential = new OAuth2Credential("twitch", "oAuthTokenHere");

// twitch client
TwitchClient twitchClient = TwitchClientBuilder.builder()
...
.withEnableChat(true)
.withChatAccount(credential)
...
.build();

A OAuth2Credential is a generic oauth credentials so the first parameter is always twitch. The 2nd value is your oauth token, you can generate a chat-bot token here.

When specifying a chat account, it must be a user access token with the chat:read scope. You also will need the chat:edit scope to be able to send messages. Alternatively, you can join chat anonymously (in read-only mode) by omitting withChatAccount.

When you build a TwitchClient Twitch4J will automatically connect you to chat (via WebSocket). So you can start joining channels and listening to messages after this - refer to the methods documented above.

Use Standalone

If you are only using the chat module, instead of creating TwitchClientBuilder, you can use TwitchChatBuilder:

ITwitchChat client = TwitchChatBuilder.builder()
.withChatAccount(oAuth2CredentialHere)
.build();