Skip to main content
Home

latest
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
58%
Published
2 months ago (0.11.4)

twitch_irc

Twitch chat client

Usage in Deno

import * as TwitchIrc from "https://deno.land/x/twitch_irc/mod.ts";

const channel = /*...*/;
const nick = /*...*/;
const pass = /*...*/;

const client = new TwitchIrc.Client({
  credentials: { nick, pass }
});
client.on("privmsg", ({ user, message }) => {
  console.log(`${user.login}: ${message}`);
});
client.on("open", () => {
  client.join(channel);
});

Usage in Node

$ npm install twitch_irc@npm:@jprochazk/twitch_irc

ESM:

// index.mjs
// or index.js, but with "type":"module" in package.json
import * as TwitchIrc from "twitch_irc";

const channel = /*...*/;
const nick = /*...*/;
const pass = /*...*/;

const client = new TwitchIrc.Client({
  credentials: { nick, pass }
});
client.on("privmsg", ({ user, message }) => {
  console.log(`${user.login}: ${message}`);
});
client.on("open", () => {
  client.join(channel);
});

CommonJS:

// index.js
const TwitchIrc = require("twitch_irc");

const channel = /*...*/;
const nick = /*...*/;
const pass = /*...*/;

const client = new TwitchIrc.Client({
  credentials: { nick, pass }
});
client.on("privmsg", ({ user, message }) => {
  console.log(`${user.login}: ${message}`);
});
client.on("open", () => {
  client.join(channel);
});

Features

  • Connection management
    • Authentication
    • Automatic reconnect
    • Automatic keep-alive
  • Correct message parsing[^1]
  • Same message bypass for PRIVMSG
  • Auto-complete tag names
  • Latency measurement
  • Strong type safety[^2]
  • Rate limiting

[^1]: Some tag values can have a space in them, and the example parser by Twitch will not correctly handle that case. [^2]: The library uses string and template literal types extensively, for example to ensure that a channel has the # prefix - similar usage of these advanced type features simplifies the internals of the library greatly, and contributes towards making it less error prone to use.

Examples

Specify the --inspect-brk flag to inspect any of the examples using developer tools. For example, for Chrome it's chrome://inspect -> Open dedicated DevTools for Node. The client is available on the globalThis object as globalThis.client.

Simple chat logging (anonymous)

Requires the CHANNEL environment variable to be specified in the format #<name>, e.g. #jtv.

$ deno run \
  --allow-env=CHANNEL \
  --allow-net=irc-ws.chat.twitch.tv \
  https://deno.land/x/twitch_irc/examples/logs.ts

Simple bot

Requires three environment variables:

  • CHANNEL in the format #<name>, e.g. #jtv.
  • TOKEN in the format oauth:<token>, e.g. oauth:abcdefg0123456789. You can generate one here.
  • LOGIN, which is the username of the account you used to generate TOKEN.

The bot will join CHANNEL upon connecting, and you can type !ping in command to have it respond to you. It will also join its own channel.

$ deno run \
  --allow-env=CHANNEL,LOGIN,TOKEN \
  --allow-net=irc-ws.chat.twitch.tv \
  https://deno.land/x/twitch_irc/examples/bot.ts

Release process

  • Commit latest changes
  • Tag with new version according to semver
  • deno run -A ./scripts/build_npm.ts <version> using the same version
  • cd npm && npm publish --access=public

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@dduel/twitch-irc

Import symbol

import * as twitch_irc from "@dduel/twitch-irc";
or

Import directly with a jsr specifier

import * as twitch_irc from "jsr:@dduel/twitch-irc";

Add Package

pnpm i jsr:@dduel/twitch-irc
or (using pnpm 10.8 or older)
pnpm dlx jsr add @dduel/twitch-irc

Import symbol

import * as twitch_irc from "@dduel/twitch-irc";

Add Package

yarn add jsr:@dduel/twitch-irc
or (using Yarn 4.8 or older)
yarn dlx jsr add @dduel/twitch-irc

Import symbol

import * as twitch_irc from "@dduel/twitch-irc";

Add Package

vlt install jsr:@dduel/twitch-irc

Import symbol

import * as twitch_irc from "@dduel/twitch-irc";

Add Package

npx jsr add @dduel/twitch-irc

Import symbol

import * as twitch_irc from "@dduel/twitch-irc";

Add Package

bunx jsr add @dduel/twitch-irc

Import symbol

import * as twitch_irc from "@dduel/twitch-irc";