Guide

Subscribe to Events

Learn how to subscribe to events from your Streamer.bot WebSocket Server
Streamer.bot will not send any events to your client until a subscription has been requested.

Handling Events with .on()

This is the recommended method for easily subscribing to WebSocket events

Utilizing the client.on() method will make your life easier by:

  • Automatically handling event subscriptions for the requested events
  • Utilizing [source].[name] event shorthand for registering new event listeners
  • Allow you to easily handle event data for specific events or groups of events by defining inline event callbacks

Examples

Subscribe to a specific event, with callback:

// Subscribe to Twitch ChatMessage events
client.on('Twitch.ChatMessage', (data) => {
  console.log('New Twitch Chat Message:', data);
});

You can subscribe to all events of a specific source with "[sourceName].*"

// Subscribe to all Twitch events
client.on('Twitch.*', (data) => {
  console.log('Twitch Event Received:' data);
});

If you want to subscribe to all event sources & events from Streamer.bot, simply pass "*"

client.on('*', (data) => {
  console.log('Event Received:', data);
});
Explore the Events API Reference to see all possible event sources and types

Manually manage subscriptions

You can also manually define event subscriptions using the following methods.

These methods all support the legacy Event Subscription Format which the Streamer.bot WebSocket API expects.

On Connect

Define the events subscriptions you need when initializing your client.

You can subscribe to all events with "*" or pass a configuration object:

// Creating a new client and automatically subscribing to all events from Streamer.bot
const client = new StreamerbotClient({
  subscribe: '*'
});

// Creating a new client and automatically subscribing to specific events
const client = new StreamerbotClient({
  subscribe: {
    'Twitch': ['ChatMessage']
  }
});

Subscribe Method

The client.subscribe() method interacts directly with the Streamer.bot WebSocket API.

You can subscribe to all events with "*" or pass a configuration object:

// Subscribe to all events from Streamer.bot
await client.subscribe('*');

// Subscribe to specific events
await client.subscribe({
  'Twitch': ['ChatMessage']
});

Unsubscribe Method

Manually unsubscribe from any existing event subscriptions.

The client.unsubscribe() method accepts the same format as the Subscribe.

// Unsubscribe to all events from Streamer.bot
await client.unsubscribe('*');

// Unsubscribe from specific events
await client.subscribe({
  'Twitch': ['ChatMessage']
});