Install using npm:
npm i tmi.js
const tmi = require('tmi.js');
const client = new tmi.Client({
connection: { reconnect: true },
channels: [ 'my_name' ]
});
client.connect();
client.on('message', (channel, tags, message, self) => {
// "Alca: Hello, World!"
console.log(`${tags['display-name']}: ${message}`);
});
const tmi = require('tmi.js');
const client = new tmi.Client({
options: { debug: true },
connection: { reconnect: true },
identity: {
username: 'my_bot_name',
password: 'oauth:my_bot_token'
},
channels: [ 'my_name' ]
});
client.connect();
client.on('message', (channel, tags, message, self) => {
// Ignore echoed messages.
if(self) return;
if(message.toLowerCase() === '!hello') {
// "@alca, heya!"
client.say(channel, `@${tags.username}, heya!`);
}
});
client.on('message', (channel, tags, message, self) => {
if(self || !message.startsWith('!')) return;
const args = message.slice(1).split(' '):
const command = args.shift().toLowerCase();
if(command === 'echo') {
client.say(channel, `@${tags.username}, you said: "${args.join(' ')}"`);
}
});