twitcheasy-twitch-bottwitch-authtwitch-auth-tmitwitch-chat-clienttwitch-eventsubtwitch-pubsub-clienttwitch-webhooks

ChatClient

An interface to Twitch chat.

Overview

Constructor

new ChatClient(authProvider, options)

Creates a new Twitch chat client.

ParameterTypeDescription
authProvider?AuthProvider

The AuthProvider instance to use for authentication.

options
ChatClientOptions

Events

onAction((channel, user, message, msg) => { /* ... */ })

Fires when a user sends an action (/me) to a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel the action was sent to.

userstringnone

The user that send the action.

messagestringnone

The action text.

msgTwitchPrivateMessagenone

The full message object containing all message and user information.

onAuthenticationFailure((message) => { /* ... */ })

Fires when authentication fails.

ParameterTypeRequiredDefaultDescription
messagestringnone

The message text.

onBan((channel, user) => { /* ... */ })

Fires when a user is permanently banned from a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel the user is banned from.

userstringnone

The banned user.

onBitsBadgeUpgrade((channel, user, upgradeInfo, msg) => { /* ... */ })

Fires when a user upgrades their bits badge in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the bits badge was upgraded.

userstringnone

The user that has upgraded their bits badge.

upgradeInfoChatBitsBadgeUpgradeInfononenone
msgUserNoticenone

The full message object containing all message and user information.

onChatClear((channel) => { /* ... */ })

Fires when the chat of a channel is cleared.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel whose chat is cleared.

onCommunityPayForward((channel, user, forwardInfo, msg) => { /* ... */ })

Fires when a user pays forward a subscription that was gifted to them to the community.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the gift was forwarded.

userstringnone

The user that forwarded the gift.

forwardInfoChatCommunityPayForwardInfonone

Additional information about the gift.

msgUserNoticenone

The full message object containing all message and user information.

onCommunitySub((channel, user, subInfo, msg) => { /* ... */ })

Fires when a user gifts random subscriptions to the community of a channel.

Community subs also fire multiple onSubGift events. To prevent alert spam, check Sub gift spam.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that was subscribed to.

userstringnone

The gifting user.

subInfoChatCommunitySubInfonone

Additional information about the community subscription.

msgUserNoticenone

The full message object containing all message and user information.

onEmoteOnly((channel, enabled) => { /* ... */ })

Fires when emote-only mode is toggled in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where emote-only mode is being toggled.

enabledbooleannone

Whether emote-only mode is being enabled. If false, it's being disabled.

onFollowersOnly((channel, enabled, delay) => { /* ... */ })

Fires when followers-only mode is toggled in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where followers-only mode is being toggled.

enabledbooleannone

Whether followers-only mode is being enabled. If false, it's being disabled.

delaynumbernone

The time (in minutes) a user needs to follow the channel to be able to talk. Only available when enabled === true.

onGiftPaidUpgrade((channel, user, subInfo, msg) => { /* ... */ })

Fires when a user upgrades their gift subscription to a paid subscription in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the subscription was upgraded.

userstringnone

The user that upgraded their subscription.

subInfoChatSubGiftUpgradeInfonone

Additional information about the subscription upgrade.

msgUserNoticenone

The full message object containing all message and user information.

onHost((channel, target, viewers) => { /* ... */ })

Fires when a channel hosts another channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The hosting channel.

targetstringnone

The channel that is being hosted.

viewersnumbernone

The number of viewers in the hosting channel.

If you're not logged in as the owner of the channel, this is undefined.

onHosted((channel, byChannel, auto, viewers) => { /* ... */ })

Fires when a channel you're logged in as its owner is being hosted by another channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that is being hosted.

byChannelstringnone

The hosting channel.

autobooleannone

Whether the host was triggered automatically (by Twitch's auto-host functionality).

viewersnumbernone

The number of viewers in the hosting channel.

onHostsRemaining((channel, numberOfHosts) => { /* ... */ })

Fires when Twitch tells you the number of hosts you have remaining in the next half hour for the channel for which you're logged in as owner after hosting a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The hosting channel.

numberOfHostsnumbernone

The number of hosts remaining in the next half hour.

onJoin((channel, user) => { /* ... */ })

Fires when a user joins a channel.

The join/part events are cached by the Twitch chat server and will be batched and sent every 30-60 seconds.

Please note that unless you enabled the requestMembershipEvents option, this will only react to your own joins.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that is being joined.

userstringnone

The user that joined.

onMessage((channel, user, message, msg) => { /* ... */ })

Fires when a user sends a message to a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel the message was sent to.

userstringnone

The user that send the message.

messagestringnone

The message text.

msgTwitchPrivateMessagenone

The full message object containing all message and user information.

onMessageFailed((channel, reason) => { /* ... */ })

Fires when sending a message fails.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that rejected the message.

reasonstringnone

The reason for the failure, e.g. you're banned (msg_banned)

onMessageRatelimit((channel, message) => { /* ... */ })

Fires when a message you tried to send gets rejected by the ratelimiter.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that was attempted to send to.

messagestringnone

The message text.

onMessageRemove((channel, messageId, msg) => { /* ... */ })

Fires when a single message is removed from a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the message was removed.

messageIdstringnone

The ID of the message that was removed.

msgClearMsgnone

The full message object containing all message and user information.

This is not the message that was removed. The text of the message is available using msg.params.message though.

onNoPermission((channel, message) => { /* ... */ })

Fires when you tried to execute a command you don't have sufficient permission for.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that a command without sufficient permissions was executed on.

messagestringnone

The message text.

onPart((channel, user) => { /* ... */ })

Fires when a user leaves ("parts") a channel.

The join/part events are cached by the Twitch chat server and will be batched and sent every 30-60 seconds.

Please note that unless you enabled the requestMembershipEvents option, this will only react to your own parts.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that is being left.

userstringnone

The user that left.

onPrimeCommunityGift((channel, user, subInfo, msg) => { /* ... */ })

Fires when a user gifts a Twitch Prime benefit to the channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the benefit was gifted.

userstringnone

The user that received the gift.

WARNING: This is a display name and thus will not work as an identifier for the API (login) in some cases.

subInfoChatPrimeCommunityGiftInfonone

Additional information about the gift.

msgUserNoticenone

The full message object containing all message and user information.

onPrimePaidUpgrade((channel, user, subInfo, msg) => { /* ... */ })

Fires when a user upgrades their Prime subscription to a paid subscription in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the subscription was upgraded.

userstringnone

The user that upgraded their subscription.

subInfoChatSubUpgradeInfonone

Additional information about the subscription upgrade.

msgUserNoticenone

The full message object containing all message and user information.

onPrivmsg((channel, user, message, msg) => { /* ... */ })

Deprecated.

Use onMessage instead.

Fires when a user sends a message to a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel the message was sent to.

userstringnone

The user that send the message.

messagestringnone

The message text.

msgTwitchPrivateMessagenone

The full message object containing all message and user information.

onR9k((channel, enabled) => { /* ... */ })

Fires when R9K mode is toggled in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where R9K mode is being toggled.

enabledbooleannone

Whether R9K mode is being enabled. If false, it's being disabled.

onRaid((channel, user, raidInfo, msg) => { /* ... */ })

Fires when a user raids a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that was raided.

userstringnone

The user that has raided the channel.

raidInfoChatRaidInfonone

Additional information about the raid.

msgUserNoticenone

The full message object containing all message and user information.

onRaidCancel((channel, msg) => { /* ... */ })

Fires when a user cancels a raid.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the raid was cancelled.

msgUserNoticenone

The full message object containing all message and user information.

onResub((channel, user, subInfo, msg) => { /* ... */ })

Fires when a user resubscribes to a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that was resubscribed to.

userstringnone

The resubscribing user.

subInfoChatSubInfonone

Additional information about the resubscription.

msgUserNoticenone

The full message object containing all message and user information.

onRewardGift((channel, user, rewardGiftInfo, msg) => { /* ... */ })

Fires when a user gifts rewards during a special event.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the rewards were gifted.

userstringnone

The user that gifted the rewards.

rewardGiftInfoChatRewardGiftInfonone

Additional information about the reward gift.

msgUserNoticenone

The full message object containing all message and user information.

onRitual((channel, user, ritualInfo, msg) => { /* ... */ })

Fires when a user performs a "ritual" in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the ritual was performed.

userstringnone

The user that has performed the ritual.

ritualInfoChatRitualInfonone

Additional information about the ritual.

msgUserNoticenone

The full message object containing all message and user information.

onSlow((channel, enabled, delay) => { /* ... */ })

Fires when slow mode is toggled in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where slow mode is being toggled.

enabledbooleannone

Whether slow mode is being enabled. If false, it's being disabled.

delaynumbernone

The time (in seconds) a user has to wait between sending messages. Only set when enabling slow mode.

onStandardPayForward((channel, user, forwardInfo, msg) => { /* ... */ })

Fires when a user pays forward a subscription that was gifted to them to a specific user.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the gift was forwarded.

userstringnone

The user that forwarded the gift.

forwardInfoChatStandardPayForwardInfonone

Additional information about the gift.

msgUserNoticenone

The full message object containing all message and user information.

onSub((channel, user, subInfo, msg) => { /* ... */ })

Fires when a user subscribes to a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that was subscribed to.

userstringnone

The subscribing user.

subInfoChatSubInfonone

Additional information about the subscription.

msgUserNoticenone

The full message object containing all message and user information.

onSubExtend((channel, user, subInfo, msg) => { /* ... */ })

Fires when a user extends their subscription using a Sub Token.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where the subscription was extended.

userstringnone

The user that extended their subscription.

subInfoChatSubExtendInfonone

Additional information about the subscription extension.

msgUserNoticenone

The full message object containing all message and user information.

onSubGift((channel, user, subInfo, msg) => { /* ... */ })

Fires when a user gifts a subscription to a channel to another user.

Community subs also fire multiple onSubGift events. To prevent alert spam, check Sub gift spam.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel that was subscribed to.

userstringnone

The user that the subscription was gifted to. The gifting user is defined in subInfo.gifter.

subInfoChatSubGiftInfonone

Additional information about the subscription.

msgUserNoticenone

The full message object containing all message and user information.

onSubsOnly((channel, enabled) => { /* ... */ })

Fires when sub only mode is toggled in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where sub only mode is being toggled.

enabledbooleannone

Whether sub only mode is being enabled. If false, it's being disabled.

onTimeout((channel, user, duration) => { /* ... */ })

Fires when a user is timed out from a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel the user is timed out from.

userstringnone

The timed out user.

durationnumbernone

The duration of the timeout, in seconds.

onUnhost((channel) => { /* ... */ })

Fires when host mode is disabled in a channel.

ParameterTypeRequiredDefaultDescription
channelstringnone

The channel where host mode is being disabled.

onWhisper((user, message, msg) => { /* ... */ })

Fires when receiving a whisper from another user.

ParameterTypeRequiredDefaultDescription
userstringnone

The user that sent the whisper.

messagestringnone

The message text.

msgWhispernone

The full message object containing all message and user information.

Properties

onAnyMessage

Type: (handler: (msg: Message) => void) => Listener

onConnect

Type: (handler: () => void) => Listener

onCtcp

Type: (handler: (target: string, user: string, command: string, params: string, msg: PrivateMessage) => void) => Listener

onCtcpReply

Type: (handler: (target: string, user: string, command: string, params: string, msg: Notice) => void) => Listener

onDisconnect

Type: (handler: (manually: boolean, reason: Error) => void) => Listener

onNickChange

Type: (handler: (oldNick: ?string, newNick: string, msg: NickChange) => void) => Listener

onNotice

Type: (handler: (target: string, user: string, message: string, msg: Notice) => void) => Listener

onRegister

Type: (handler: () => void) => Listener

currentNick

Type: string

isConnected

Type: boolean

isConnecting

Type: boolean

isRegistered

Type: boolean

port

Type: number

serverProperties

Type: ServerProperties

Methods

anonymous(options)

static

Creates a new anonymous Twitch chat client.

ParameterTypeDescription
options
ChatClientOptions
Return type: ChatClient

forTwitchClient(authProvider, options)

static
Deprecated.

Use the ChatClient constructor instead.

Creates a new Twitch chat client with the user info from the {@AuthProvider} instance.

ParameterTypeDescription
authProviderAuthProvider

The AuthProvider instance to use for authentication.

options
ChatClientOptions
Return type: ChatClient

action(channel, message)

async

Sends an action message (/me) to a channel.

ParameterTypeDescription
channelstring

The channel to send the message to.

messagestring

The message to send.

Return type: void

addCapability(cap)

ParameterTypeDescription
capCapabilitynone
Return type: void

addListener<Args>(event, listener)

ParameterTypeDescription
eventEventBinder<Args>none
listenerEventHandler<Args>none
Return type: Listener

addVip(channel, user)

async

Gives a user VIP status in a channel.

ParameterTypeDescription
channelstring

The channel to give the user VIP status in.

userstring

The user to give VIP status.

Return type: void

addVIP(channel, user)

async
Deprecated.

Use addVip instead.

ParameterTypeDescription
channelstringnone
userstringnone
Return type: void

ban(channel, user, reason)

async

Bans a user from a channel.

ParameterTypeDescription
channel?string

The channel to ban the user from. Defaults to the channel of the connected user.

userstring

The user to ban from the channel.

reasonstring

The reason for the ban.

Return type: void

changeColor(color)

async

Changes your username color.

ParameterTypeDescription
colorstring

The hexadecimal code (prefixed with #) or color name to use for your username.

Please note that only Twitch Turbo or Prime users can use hexadecimal codes for arbitrary colors.

If you have neither of those, you can only choose from the following color names:

Blue, BlueViolet, CadetBlue, Chocolate, Coral, DodgerBlue, Firebrick, GoldenRod, Green, HotPink, OrangeRed, Red, SeaGreen, SpringGreen, YellowGreen

Return type: void

clear(channel)

async

Clears all messages in a channel.

ParameterTypeDescription
channelstring

The channel to ban the user from. Defaults to the channel of the connected user.

Return type: void

connect()

async
Return type: void

createMessage<T>(type, params, tags)

ParameterTypeDescription
typeMessageConstructor<T>none
paramsPartial<MessageParamValues<T>>none
tagsRecord<string, string>none
Return type: T

deleteMessage(channel, message)

async

Deletes a message from a channel.

ParameterTypeDescription
channelstring

The channel to delete the message from.

messagestring | TwitchPrivateMessage

The message (as message ID or message object) to delete.

Return type: void

disableEmoteOnly(channel)

async

Disables emote-only mode in a channel.

ParameterTypeDescription
channelstring

The channel to disable emote-only mode in.

Return type: void

disableFollowersOnly(channel)

async

Disables followers-only mode in a channel.

ParameterTypeDescription
channelstring

The channel to disable followers-only mode in.

Return type: void

disableR9k(channel)

async

Disables r9k mode in a channel.

ParameterTypeDescription
channelstring

The channel to disable r9k mode in.

Return type: void

disableSlow(channel)

async

Disables slow mode in a channel.

ParameterTypeDescription
channelstring

The channel to disable slow mode in.

Return type: void

disableSubsOnly(channel)

async

Disables subscribers-only mode in a channel.

ParameterTypeDescription
channelstring

The channel to disable subscribers-only mode in.

Return type: void

enableEmoteOnly(channel)

async

Enables emote-only mode in a channel.

ParameterTypeDescription
channelstring

The channel to enable emote-only mode in.

Return type: void

enableFollowersOnly(channel, minFollowTime)

async

Enables followers-only mode in a channel.

ParameterTypeDescription
channelstring

The channel to enable followers-only mode in.

minFollowTimenumber

The time (in minutes) a user needs to be following before being able to send messages.

Return type: void

enableR9k(channel)

async

Enables r9k mode in a channel.

ParameterTypeDescription
channelstring

The channel to enable r9k mode in.

Return type: void

enableSlow(channel, delayBetweenMessages)

async

Enables slow mode in a channel.

ParameterTypeDescription
channelstring

The channel to enable slow mode in.

delayBetweenMessagesnumber

The time (in seconds) a user needs to wait between messages.

Return type: void

enableSubsOnly(channel)

async

Enables subscribers-only mode in a channel.

ParameterTypeDescription
channelstring

The channel to enable subscribers-only mode in.

Return type: void

getCommandClass(command)

ParameterTypeDescription
commandstringnone
Return type: ?MessageConstructor

getMods(channel)

async

Retrieves a list of moderators in a channel.

ParameterTypeDescription
channelstring

The channel to retrieve the moderators of.

Return type: Array<string>

getVips(channel)

async

Retrieves a list of VIPs in a channel.

ParameterTypeDescription
channelstring

The channel to retrieve the VIPs of.

Return type: Array<string>

getVIPs(channel)

async
Deprecated.

Use getVips instead.

ParameterTypeDescription
channelstringnone
Return type: Array<string>

host(channel, target)

async

Hosts a channel on another channel.

ParameterTypeDescription
channel?string

The host source, i.e. the channel that is hosting. Defaults to the channel of the connected user.

targetstring

The host target, i.e. the channel that is being hosted.

Return type: void

join(channel)

async

Joins a channel.

ParameterTypeDescription
channelstring

The channel to join.

Return type: void

knowsCommand(command)

ParameterTypeDescription
commandstringnone
Return type: boolean

mod(channel, user)

async

Gives a user moderator rights in a channel.

ParameterTypeDescription
channelstring

The channel to give the user moderator rights in.

userstring

The user to give moderator rights.

Return type: void

on<Args>(event, listener)

ParameterTypeDescription
eventEventBinder<Args>none
listenerEventHandler<Args>none
Return type: Listener

onNamedMessage<T>(commandName, handler, handlerName)

ParameterTypeDescription
commandNamestringnone
handlerEventHandler<T>none
handlerNamestringnone
Return type: string

onTypedMessage<T>(type, handler, handlerName)

ParameterTypeDescription
typeMessageConstructor<T>none
handlerEventHandler<T>none
handlerNamestringnone
Return type: string

part(channel)

Leaves a channel ("part" in IRC terms).

ParameterTypeDescription
channelstring

The channel to leave.

Return type: void

pingCheck()

Return type: void

purge(channel, user, reason)

async

Removes all messages of a user from a channel.

ParameterTypeDescription
channelstring

The channel to purge the user's messages from.

userstring

The user to purge.

reasonstring

The reason for the purge.

Return type: void

quit()

async

Disconnects from the chat server.

Return type: void

receiveLine(line)

ParameterTypeDescription
linestringnone
Return type: void

reconnect(message)

async
ParameterTypeDescription
messagestringnone
Return type: void

registerCapability(cap)

async
ParameterTypeDescription
capCapabilitynone
Return type: Array<ServerCapability> | Error

registerEvent<T>()

Return type: EventBinder<T>

registerMessageType(cls)

ParameterTypeDescription
clsMessageConstructornone
Return type: void

removeListener(id)

ParameterTypeDescription
idListenernone
Return type: void

removeListener(event, listener)

ParameterTypeDescription
eventFunctionnone
listenerFunctionnone
Return type: void

removeMessageListener(handlerName)

ParameterTypeDescription
handlerNamestringnone
Return type: void

removeVip(channel, user)

async

Takes VIP status from a user in a channel.

ParameterTypeDescription
channelstring

The channel to remove the user's VIP status in.

userstring

The user to take VIP status from.

Return type: void

removeVIP(channel, user)

async
Deprecated.

Use removeVip instead.

ParameterTypeDescription
channelstringnone
userstringnone
Return type: void

runCommercial(channel, duration)

async

Runs a commercial break on a channel.

ParameterTypeDescription
channelstring

The channel to run the commercial break on.

duration
CommercialLength

The possible lengths of a channel commercial.

Aliased type: 30 | 60 | 90 | 120 | 150 | 180

The duration of the commercial break.

Return type: void

say(channel, message, attributes)

async

Sends a message to a channel.

ParameterTypeDescription
channelstring

The channel to send the message to.

messagestring

The message to send.

attributesChatSayMessageAttributes

The attributes to add to the message.

Return type: void

send(message)

ParameterTypeDescription
messageMessagenone
Return type: void

sendCtcp(target, type, message)

ParameterTypeDescription
targetstringnone
typestringnone
messagestringnone
Return type: void

sendMessage<T>(type, params, tags)

ParameterTypeDescription
typeMessageConstructor<T>none
paramsPartial<MessageParamValues<T>>none
tagsRecord<string, string>none
Return type: void

sendMessageAndCaptureReply<T>(type, params)

async
ParameterTypeDescription
typeMessageConstructor<T>none
paramsPartial<MessageParamValues<T>>none
Return type: Array<Message>

sendRaw(line)

ParameterTypeDescription
linestringnone
Return type: void

timeout(channel, user, duration, reason)

async

Times out a user in a channel and removes all their messages.

ParameterTypeDescription
channelstring

The channel to time out the user in.

userstring

The user to time out.

durationnumber

The time (in seconds) until the user can send messages again. Defaults to 1 minute.

reasonstring
Return type: void

unhost(channel)

async

Ends any host on a channel.

This only works when in the channel that was hosted in order to provide feedback about success of the command.

If you don't need this feedback, consider using ChatClient#unhostOutside instead.

ParameterTypeDescription
channelstring

The channel to end the host on. Defaults to the channel of the connected user.

Return type: void

unhostOutside(channel)

async

Ends any host on a channel.

This works even when not in the channel that was hosted, but provides no feedback about success of the command.

If you need feedback about success, use ChatClient#unhost (but make sure you're in the channel you are hosting).

ParameterTypeDescription
channelstring

The channel to end the host on. Defaults to the channel of the connected user.

Return type: void

unmod(channel, user)

async

Takes moderator rights from a user in a channel.

ParameterTypeDescription
channelstring

The channel to remove the user's moderator rights in.

userstring

The user to take moderator rights from.

Return type: void

waitForRegistration()

async
Deprecated.

Use the onRegister event instead. To join channels after connecting, use the channels option.

Waits for authentication (or "registration" in IRC terms) to finish.

Return type: void

whisper(user, message)

async

Sends a whisper message to another user.

ParameterTypeDescription
userstring

The user to send the message to.

messagestring

The message to send.

Return type: void