Requesting Twitch-specific capabilities
Twitch capabilities expose your bot to more messages and metadata than it would normally receive, which enriches the experience your bot can provide. By using the REQ
subcommand specified in the IRC v3 capability negotiation specification, your bot can request the following Twitch-specific capabilities.
Capability | Description |
---|---|
twitch.tv/commands | Lets your bot send PRIVMSG messages that include Twitch chat commands and receive Twitch-specific IRC messages. |
twitch.tv/membership | Lets your bot receive JOIN and PART messages when users join and leave the chat room. |
twitch.tv/tags | Adds additional metadata to the command and membership messages. For the list of metadata available with each message, see Twitch tags. To request the tags capability, you must also request the commands capability. |
Note that the capability strings are case sensitive.
To request Twitch-specific command messages like GLOBALUSERSTATE
, ROOMSTATE
, and USERSTATE
, send the following commands capability message.
CAP REQ :twitch.tv/commands
As you can see, the messages aren’t very useful:
:tmi.twitch.tv GLOBALUSERSTATE
:tmi.twitch.tv USERSTATE #foo
:tmi.twitch.tv ROOMSTATE #foo
But if you also request the tags capability:
CAP REQ :twitch.tv/commands twitch.tv/tags
You’ll get much richer messages:
@badge-info=;badges=;color=#0000FF;display-name=barbar;emote-sets=0,300374282;user-id=713936733;user-type= :tmi.twitch.tv GLOBALUSERSTATE
@badge-info=;badges=;color=#0000FF;display-name=barbar;emote-sets=0,300374282;mod=0;subscriber=0;user-type= :tmi.twitch.tv USERSTATE #barbar
@emote-only=0;followers-only=-1;r9k=0;rituals=0;room-id=728719755;slow=10;subs-only=0 :tmi.twitch.tv ROOMSTATE #barbar
If your capabilities request succeeds, Twitch replies with the standard ACK subcommand message.
:tmi.twitch.tv CAP * ACK :twitch.tv/commands twitch.tv/tags
If your bot requests a capability that the Twitch IRC server doesn’t support, the server replies with the standard NAK
subcommand message that identifies the capabilities that were denied.
CAP * NAK :twitch.tv/foo
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/tags twitch.tv/commands');
});
Next steps
After requesting capabilities, the next step is to authenticate your bot with the Twitch IRC server.