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

Setting up a tmi.js client

This package is generally used like tmi.js is normally, with just a single minor change.

It completely ignores the identity option, and instead takes an authProvider option which takes an AuthProvider instance that can be used for other twitch packages as well.

This also offers the additional benefit of being able to refresh tokens internally using a refreshable AuthProvider.

Example

Taken from the tmi.js README and adapted for this package:

const tmi = require('twitch-auth-tmi');
const { StaticAuthProvider } = require('twitch-auth');
const authProvider = new StaticAuthProvider('my-client-id', 'my-bot-token');
const client = new tmi.Client({
	options: { debug: true, messagesLogLevel: 'info' },
	connection: {
		reconnect: true,
		secure: true
	},
	authProvider: authProvider,
	channels: ['my-channel']
});
client.connect().catch(console.error);
client.on('message', (channel, tags, message, self) => {
	if (self) return;
	if (message.toLowerCase() === '!hello') {
		client.say(channel, `@${tags.username}, heya!`);
	}
});