Last active
December 16, 2019 08:06
-
-
Save bjarneo/7a8bb1f463c7a7e2608b7d9c28b97916 to your computer and use it in GitHub Desktop.
Basic twitch chat bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tmi = require('tmi.js'); | |
// Define configuration options | |
const opts = { | |
identity: { | |
username: 'your_username', | |
password: 'oauth:your_secret_password' // get the password from https://twitchapps.com/tmi/ | |
}, | |
channels: ['your_channel_name'] | |
}; | |
// Create a client with our options | |
const client = new tmi.client(opts); | |
// Register our event handlers (defined below) | |
client.on('message', onMessageHandler); | |
client.on('connected', onConnectedHandler); | |
// Connect to Twitch: | |
client.connect(); | |
// Called every time a message comes in | |
function onMessageHandler (target, context, msg) { | |
// Remove whitespace from chat message | |
const commandName = msg.trim(); | |
// If the command is known, let's execute it | |
if (commandName === '!specs') { | |
client.say(target, '[BOT] My specs are: Geforce 1060 6GB RAM'); | |
console.log(`* Executed ${commandName} command`); | |
} else if (commandName === '!instagram') { | |
client.say(target, '[BOT] My instagram is: https://www.instagram.com/your_instagram'); | |
} else { | |
console.log(`* Unknown command ${commandName}`); | |
} | |
} | |
// Called every time the bot connects to Twitch chat | |
function onConnectedHandler (addr, port) { | |
console.log(`* Connected to ${addr}:${port}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment