object
should be in either of the following forms:
interface EventTypes {
'event-with-parameters': any[]
'event-with-example-handler': (...args: any[]) => void
}
Chat constructor.
This command will allow you to permanently ban a user from the chat room.
This command will allow you to block all messages from a specific user in chat and whispers if you do not wish to see their comments.
Broadcast message to all connected channels.
This command will allow the Broadcaster and chat moderators to completely wipe the previous chat history.
Allows you to change the color of your username.
An Affiliate and Partner command that runs a commercial for all of your viewers.
Connect to Twitch.
Single message removal on a channel.
Disconnected from Twitch.
Calls each of the listeners registered for a given event.
This command allows you to set your room so only messages that are 100% emotes are allowed.
This command allows you to disable emote only mode if you previously enabled it.
Return an array listing the events for which the emitter has registered listeners.
This command allows you or your mods to restrict chat to all or some of your followers, based on how long they’ve followed.
Follow time from 0 minutes (all followers) to 3 months.
This command will disable followers only mode if it was previously enabled on the channel.
This command will allow you to host another channel on yours.
Join a channel.
Return the number of listeners listening to a given event.
Return the listeners registered for a given event.
Adds a stream marker (with an optional description, max 140 characters) at the current timestamp. You can use markers in the Highlighter for easier editing.
This command will color your text based on your chat name color.
This command will allow you to promote a user to a channel moderator.
This command will display a list of all chat moderators for that specific channel.
Add a listener for a given event.
Add a one-time listener for a given event.
Depart from a channel.
This command will send the viewer to another live channel.
Reconnect to Twitch, providing new options to the client.
Remove all listeners, or those of the specified event.
Remove the listeners of a given event.
Send a message to a channel.
Send a raw message to Twitch.
This command allows you to set a limit on how often users in the chat room are allowed to send messages (rate limiting).
This command allows you to disable slow mode if you had previously set it.
This command allows you to set your room so only users subscribed to you can talk in the chat room. If you don't have the subscription feature it will only allow the Broadcaster and the channel moderators to talk in the chat room.
This command allows you to disable subscribers only chat room if you previously enabled it.
This command allows you to temporarily ban someone from the chat room for 10 minutes by default. This will be indicated to yourself and the temporarily banned subject in chat on a successful temporary ban. A new timeout command will overwrite an old one.
This command will allow you to lift a permanent ban on a user from the chat room. You can also use this command to end a ban early; this also applies to timeouts.
This command will allow you to remove users from your block list that you previously added.
Using this command will revert the embedding from hosting a channel and return it to its normal state.
This command will allow you to demote an existing moderator back to viewer status (removing their moderator abilities).
This command will cancel the raid.
This command will grant VIP status to a user.
Updates the client options after instantiation.
To update token
or username
, use reconnect()
.
This command will grant VIP status to a user.
This command will display a list of VIPs for that specific channel.
This command sends a private message to another user on Twitch.
Generated using TypeDoc
Interact with Twitch chat.
Connecting
const token = 'cfabdegwdoklmawdzdo98xt2fo512y' const username = 'ronni' const { chat } = new TwitchJs({ token, username }) chat.connect().then(globalUserState => { // Do stuff ... })
Note: Connecting with a
token
and ausername
is optional.Once connected,
chat.userState
will contain global user state information.Joining a channel
const channel = '#dallas' chat.join(channel).then(channelState => { // Do stuff with channelState... })
After joining a channel,
chat.channels[channel]
will contain channel state information.Listening for events
// Listen to all events chat.on('*', message => { // Do stuff with message ... }) // Listen to private messages chat.on('PRIVMSG', privateMessage => { // Do stuff with privateMessage ... })
Events are nested; for example:
// Listen to subscriptions only chat.on('USERNOTICE/SUBSCRIPTION', userStateMessage => { // Do stuff with userStateMessage ... }) // Listen to all user notices chat.on('USERNOTICE', userStateMessage => { // Do stuff with userStateMessage ... })
For added convenience, TwitchJS also exposes event constants.
const { chat } = new TwitchJs({ token, username }) // Listen to all user notices chat.on(chat.events.USER_NOTICE, userStateMessage => { // Do stuff with userStateMessage ... })
Sending messages
To send messages, [Chat] must be initialized with a
username
and atoken
withchat_login
scope.All messages sent to Twitch are automatically rate-limited according to Twitch Developer documentation.
Speak in channel
const channel = '#dallas' chat .say(channel, 'Kappa Keepo Kappa') // Optionally ... .then(() => { // ... do stuff on success ... })
Send command to channel
All chat commands are currently supported and exposed as camel-case methods. For example:
const channel = '#dallas' // Enable followers-only for 1 week chat.followersOnly(channel, '1w') // Ban ronni chat.ban(channel, 'ronni')
Note:
Promise
-resolves for each commands are planned.Joining multiple channels
const channels = ['#dallas', '#ronni'] Promise.all(channels.map(channel => chat.join(channel))).then(channelStates => { // Listen to all messages from #dallas only chat.on('#dallas', message => { // Do stuff with message ... }) // Listen to private messages from #dallas and #ronni chat.on('PRIVMSG', privateMessage => { // Do stuff with privateMessage ... }) // Listen to private messages from #dallas only chat.on('PRIVMSG/#dallas', privateMessage => { // Do stuff with privateMessage ... }) // Listen to all private messages from #ronni only chat.on('PRIVMSG/#ronni', privateMessage => { // Do stuff with privateMessage ... }) })
Broadcasting to all channels
chat .broadcast('Kappa Keepo Kappa') // Optionally ... .then(userStateMessages => { // ... do stuff with userStateMessages on success ... })