I’m using tmi.js in node on my desktop. im trying to write a simple chatbot that listens to channels for specific commands and replies. I’m following this tutorial: https://dev.twitch.tv/docs/irc . For reference, I am testing this bot on my own channel (daalbhath) but the bot is itself a separate account (daalbot) and i generated an OAuth token for the bot account with https://twitchapps.com/tmi/
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 (channel, tags, msg, self) {
if (self) { return; } // Ignore messages from the bot
// Remove whitespace from chat message
const command: string = msg.trim();
try {
if (command.startsWith('!add-detractors')) {
const detractors: string[] = command.split(' ').slice(1);
currDetractors.push(...detractors);
if (detractors.length === 0) {
return;
}
client.say(channel, `Added ${detractors.join(', ')} to the list of detractors dspLeanin`);
} else if (command.startsWith('!list-detractors')) {
console.log('received command');
client.say(channel, `There are currently ${currDetractors.length} known detractors`);
client.say(channel, `The current detractors are: ${currDetractors.join(', ')}`);
} else {
console.log(`${channel}/${tags.username}: ${msg}`);
}
} catch (err) {
console.log(`something went wrong: ${err}`);
console.log(`msg: ${msg}`);
}
}
The bot messages don’t show up in my channel. More specifically, only 1 message showed up and then all subsequent messages did not show up. No error is logged either. When I debugged, I did not see any abnormal behavior. The PRIVMSG call is being made. console.logs show that the onMessage handler is being called per message. Literally the message just does not show up in my channel (daalbhath). I also don’t have followers only or sub only or anything enabled.