Using the Client

Connect to the Streamer.bot WebSocket Server using the official client package
The easiest way to interact with the WebSocket Server is by using the official client package

Installation

Install the package via your preferred package manager:

pnpm install @streamerbot/client

Or import it directly in the browser via a CDN:

<script src="https://cdn.jsdelivr.net/npm/@streamerbot/client/dist/streamerbot-client.js"></script>

Or with ESM modules:

<script type="module" src="index.js"></script>

Usage

To connect to the WebSocket Server using the Streamer.bot Client

const client = new StreamerbotClient();

You can also specify custom connection options, if you have changed the default settings outlined above.

const client = new StreamerbotClient({
  host: '127.0.0.1',
  port: 8080,
  endpoint: '/',
  password: 'my-secret-password' // Only needed if authentication is enabled
});
Refer to the Streamer.bot Client documentation for more details

Execute Actions

Streamer.bot Client makes it extremely easy to execute your actions:

// Execute an action with actionId "9c6203fd-363f-4834-983e-b10423c568ea"
client.doAction("9c6203fd-363f-4834-983e-b10423c568ea");

// Execute an action by name
client.doAction({ name: "My Action" })

Event Handling

To add an event handler, you can use the on() method.

Streamer.bot Client will automatically handle event subscriptions when you add an event handler!

Listening to specific events is easy, simply specify the event name, which is a combination of the event source and type.

For example, below we subscribe to Twitch Chat Message events:

// Subscribe to Twitch Chat messages and register an event handler
client.on('Twitch.ChatMessage', ({ event, data }) => {
  // Do something with Twitch Chat data...
  console.log('Twitch Chat:', data);
});

You can also subscribe to all events from a specific source by using wildcards:

// Subscribe to *All* Twitch events
client.on('Twitch.*', ({ event, data }) => {
  // Do something with Twitch data...
  console.log('Twitch Event:', event.type, data);
});

If you want to listen to all events, you can use the * wildcard:

This is not recommended for production use, as it will generate a lot of events!
// Subscribe to *All events*
client.on('*', ({ event, data }) => {
  // Do something with all events...
  console.log(`[${event.source}.${event.type}]`, data);
});