Events

Some events will only be fired if you are logged in. If you are not familiar with event listeners, please read this.

Contents

Action

Received action message on channel. (/me <message>)

Parameters:

  • channel: String - Channel name
  • user: Object - User object
  • message: String - Message received
  • self: Boolean - Message was sent by the client
client.on("action", function (channel, user, message, self) {
    // Do your stuff.
});

According to Twitch, the user object is always subject to change.

{
    color: '#FFFFFF',
    'display-name': 'Schmoopiie',
    emotes: { '25': [ '0-4' ] },
    subscriber: false,
    turbo: true,
    'user-type': 'mod',
    'emotes-raw': '25:0-4',
    username: 'schmoopiie'
}

Chat

Received message on channel.

Parameters:

  • channel: String - Channel name
  • user: Object - User object
  • message: String - Message received
  • self: Boolean - Message was sent by the client
client.on("chat", function (channel, user, message, self) {
    // Do your stuff.
});

According to Twitch, the user object is always subject to change.

{
    color: '#FFFFFF',
    'display-name': 'Schmoopiie',
    emotes: { '25': [ '0-4' ] },
    subscriber: false,
    turbo: true,
    'user-type': 'mod',
    'emotes-raw': '25:0-4',
    username: 'schmoopiie'
}

Clearchat

Chat of a channel got cleared.

Parameters:

  • channel: String - Channel name
client.on("clearchat", function (channel) {
    // Do your stuff.
});

Connected

Connected to server.

Parameters:

  • address: String - Remote address
  • port: Integer - Remote port
client.on("connected", function (address, port) {
    // Do your stuff.
});

Connecting

Connecting to a server.

Parameters:

  • address: String - Remote address
  • port: Integer - Remote port
client.on("connecting", function (address, port) {
    // Do your stuff.
});

Disconnected

Got disconnected from server.

Parameters:

  • reason: String - Reason why you got disconnected
client.on("disconnected", function (reason) {
    // Do your stuff.
});

Emotesets

Received the emote-sets from Twitch. The emote-sets contains your emote set, which you can use to request a subset of https://api.twitch.tv/kraken/chat/emoticon_images

Example: https://api.twitch.tv/kraken/chat/emoticon_images?emotesets=0,27,33,793

Parameters:

  • sets: String - Your emote sets (always contains at least 0)
client.on("emotesets", function(sets) {
    // Using our API function..
    client.api({
        url: "/chat/emoticon_images?emotesets=" + sets
    }, function(err, res, body) {
        console.log(body);
    });
});

Hosted

Channel is now hosted by another broadcaster. This event is fired only if you are logged in as the broadcaster.

Parameters:

  • channel: String - Channel name being hosted
  • username: String - Username hosting you
  • viewers: Integer - Viewers count
client.on("hosted", function (channel, username, viewers) {
    // Do your stuff.
});

Hosting

Channel is now hosting another channel.

Parameters:

  • channel: String - Channel name that is now hosting
  • target: String - Channel being hosted
  • viewers: Integer - Viewers count
client.on("hosting", function (channel, target, viewers) {
    // Do your stuff.
});

Join

Username has joined a channel. Not available on large channels and is also sent in batch every 30-60secs.

Parameters:

  • channel: String - Channel name
  • username: String - Username
client.on("join", function (channel, username) {
    // Do your stuff.
});

Logon

Connection established, sending informations to server.

client.on("logon", function () {
    // Do your stuff.
});

Mod

Someone got modded on a channel.

Important: It doesn't detect if username is a new moderator, it is triggered when jtv gives the moderator status to someone on a channel. You will see a lot of mod / unmod events on a channel. When a moderator joins a channel, it will take a few seconds for jtv to give the user the moderator status. When leaving a channel, the user gets unmodded.

Parameters:

  • channel: String - Channel name
  • username: String - Username
client.on("mod", function (channel, username) {
    // Do your stuff.
});

Mods

Received the list of moderators of a channel.

Parameters:

  • channel: String - Channel name
  • mods: Array - Moderators of the channel
client.on("mods", function (channel, mods) {
    // Do your stuff.
});

Notice

Received a notice from server. The goal of these notices is to allow the users to change their language settings and still be able to know programmatically what message was sent by the server. We encourage to use the msg-id to compare these messages.

Parameters:

  • channel: String - Channel name
  • msgid: String - Message ID (See known msg-ids below)
  • message: String - Message received

Known msg-ids:

  • already_banned: X is already banned in this room.
  • already_subs_off: This room is not in subscribers-only mode.
  • bad_ban_admin: You cannot ban admin X.
  • bad_ban_broadcaster: You cannot ban the broadcaster.
  • bad_ban_global_mod: You cannot ban global moderator X.
  • bad_ban_self: You cannot ban yourself.
  • bad_ban_staff: You cannot ban staff X.
  • bad_commercial_error: Failed to start commercial.
  • bad_mod_banned: X is banned in this room.
  • bad_timeout_admin: You cannot timeout admin X.
  • bad_timeout_global_mod: You cannot timeout global moderator X.
  • bad_timeout_self: You cannot timeout yourself.
  • bad_timeout_staff: You cannot timeout staff X.
  • bad_unban_no_ban: X is not banned from this room.
  • ban_success: X is now banned from this room.
  • cmds_available: Commands available to you in this room (use /help for details)..
  • color_changed: Your color has been changed.
  • commercial_success: Initiating X second commercial break. Please keep in mind..
  • hosts_remaining: X host commands remaining this half hour.
  • host_target_went_offline: X has gone offline. Exiting host mode
  • msg_banned: You are permanently banned from talking in channel.
  • msg_duplicate: Your message was not sent because you are sending messages too quickly.
  • msg_ratelimit: Your message was not sent because you are sending messages too quickly.
  • msg_subsonly: This room is in subscribers only mode. To talk, purchase..
  • msg_timedout: You are banned from talking in X for Y more seconds.
  • msg_verified_email: This room requires a verified email address to chat.
  • no_help: No help available.
  • no_permission: You don't have permission to perform that action.
  • timeout_success: X has been timed out for length seconds.
  • unban_success: X is no longer banned from this room.
  • unrecognized_cmd: Unrecognized command: X
  • usage_ban: Usage: "/ban " - Permanently prevent a user from chatting..
  • usage_clear: Usage: "/clear" - Clear chat history for all users in this room.
  • usage_color: Usage: "/color " - Change your username color. Color must be..
  • usage_commercial: Usage: "/commercial [length]" - Triggers a commercial.
  • usage_disconnect: Usage: "/disconnect" - Reconnects to chat.
  • usage_help: Usage: "/help" - Lists the commands available to you in this room.
  • usage_host: Usage: "/host " - Host another channel. Use "unhost" to unset host mode.
  • usage_me: Usage: "/me " - Send an "emote" message in the third person.
  • usage_mod: Usage: "/mod " - Grant mod status to a user. Use "mods" to list the..
  • usage_mods: Usage: "/mods" - Lists the moderators of this channel.
  • usage_r9k_on: Usage: "/r9kbeta" - Enables r9k mode. See http://bit.ly/bGtBDf for details.
  • usage_r9k_off: Usage: "/r9kbetaoff" - Disables r9k mode.
  • usage_slow_on: Usage: "/slow [duration]" - Enables slow mode..
  • usage_slow_off: Usage: "/slowoff" - Disables slow mode.
  • usage_subs_on: Usage: "/subscribers" - Enables subscribers-only mode..
  • usage_subs_off: Usage: "/subscribersoff" - Disables subscribers-only mode.
  • usage_timeout: Usage: "/timeout [duration]" - Temporarily prevent a user from chatting.
  • usage_unban: Usage: "/unban " - Removes a ban on a user.
  • usage_unhost: Usage: "/unhost" - Stop hosting another channel.
  • usage_unmod: Usage: "/unmod " - Revoke mod status from a user..
  • whisper_invalid_self: You cannot whisper to yourself.
  • whisper_limit_per_min: You are sending whispers too fast. Try again in a minute.
  • whisper_limit_per_sec: You are sending whispers too fast. Try again in a second.
  • whisper_restricted_recipient: That user's settings prevent them from receiving this whisper.

The following msg-ids wont be returned in the notice event because they are already available as event listeners:

  • host_off: Exited hosting mode.
  • host_on: Now hosting X
  • no_mods: There are no moderators for this room.
  • r9k_off: This room is no longer in r9k mode.
  • r9k_on: This room is now in r9k mode.
  • room_mods: The moderators of this room are X
  • slow_off: This room is no longer in slow mode.
  • slow_on: This room is now in slow mode. You may send messages every X seconds.
  • subs_off: This room is no longer in subscribers-only mode.
  • subs_on: This room is now in subscribers-only mode.
client.on("notice", function (channel, msgid, message) {
    // Do your stuff.
});

Part

User has left a channel.

Parameters:

  • channel: String - Channel name
  • username: String - Username
client.on("part", function (channel, username) {
    // Do your stuff.
});

Ping

Received PING from server.

client.on("ping", function () {
    // Do your stuff.
});

Pong

Sent a PING request ? PONG.

Parameters:

  • latency: Float - Current latency
client.on("pong", function (latency) {
    // Do your stuff.
});

R9kbeta

Channel enabled or disabled R9K mode.

Parameters:

  • channel: String - Channel name
  • enabled: Boolean - Returns true if mode is enabled or false if disabled
client.on("r9kbeta", function (channel, enabled) {
    // Do your stuff.
});

Reconnect

Trying to reconnect to server.

client.on("reconnect", function () {
    // Do your stuff.
});

Roomstate

Triggered upon joining a channel. Gives you the current state of the channel.

Parameters:

  • channel: String - Channel name
  • state: Object - Current state of the channel
client.on("roomstate", function (channel, state) {
    // Do your stuff.
});

According to Twitch, the state object is always subject to change.

{
    'broadcaster-lang': null,
    r9k: false,
    slow: false,
    'subs-only': false,
    channel: '#schmoopiie'
}

Slowmode

Channel enabled or disabled slow mode.

Parameters:

  • channel: String - Channel name
  • enabled: Boolean - Returns true if mode is enabled or false if disabled
  • length: Integer - Slow length value
client.on("slowmode", function (channel, enabled, length) {
    // Do your stuff.
});

Subanniversary

Username has shared how many months he/she has been a subscriber on a channel.

Parameters:

  • channel: String - Channel name
  • username: String - Username
  • months: Integer - How many months
client.on("subanniversary", function (channel, username, months) {
    // Do your stuff.
});

Subscribers

Channel enabled or disabled subscribers-only mode.

Parameters:

  • channel: String - Channel name
  • enabled: Boolean - Returns true if mode is enabled or false if disabled
client.on("subscribers", function (channel, enabled) {
    // Do your stuff.
});

Subscription

Username has subscribed to a channel.

Parameters:

  • channel: String - Channel name
  • username: String - Username
client.on("subscription", function (channel, username) {
    // Do your stuff.
});

Timeout

Username has been timed out on a channel.

Parameters:

  • channel: String - Channel name
  • username: String - Username
client.on("timeout", function (channel, username) {
    // Do your stuff.
});

Unhost

Channel ended the current hosting.

Parameters:

  • channel: String - Channel name
  • viewers: Integer - Viewer count
client.on("unhost", function (channel, viewers) {
    // Do your stuff.
});

Unmod

Someone got unmodded on a channel.

Important: It doesn't detect if username got removed from moderators list. You will see a lot of mod / unmod events on a channel. When a moderator joins a channel, it will take a few seconds for jtv to give the user the moderator status. When leaving a channel, the user gets unmodded.

Parameters:

  • channel: String - Channel name
  • username: String - Username
client.on("unmod", function (channel, username) {
    // Do your stuff.
});

Whisper

Received a whisper.

Important: You have to be connected to a group chat server to send or receive whispers.

Parameters:

  • username: String - Username
  • message: String - Message
client.on("whisper", function (username, message) {
    // Do your stuff.
});