-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
45 lines (36 loc) · 1.08 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const tmi = require('tmi.js');
// Define configuration options
const opts = {
identity: {
username: '[your_bot_twitch_username]',
password: 'oath:[your_bot_twitch_oauth_token]'
},
channels: [
'[your_twitch_channel]'
]
};
// Create a client with our options
const client = new tmi.client(opts);
// Register event handlers
client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler);
// Connect to Twitch
client.connect();
// Called every time a message is received
function onMessageHandler(target, context, msg, self) {
// Ignore messages from the bot
if (self) return;
// Remove whitespace from chat message
const command = msg.trim();
// Handle different commands
if (command === '!hello') {
client.say(target, 'Hello, Twitch chat!');
}
// Add more commands here...
// Log the message to the console
console.log(`[${target} (${context['message-type']})] ${context.username}: ${msg}`);
}
// Called every time the bot connects to Twitch chat
function onConnectedHandler(addr, port) {
console.log(`Connected to ${addr}:${port}`);
}