Twitch Bot ~ Philips Hue system


I am working on a Twitch Bot with Philips Hue intergration.

I have gotten the core futures to work. (Sub change color) But when i try to add “Cheer” system the bot recognise it but dosnt send it to the “hue” script.

so if there is anyone out there that have done this with NodeJS i would love your help!

This is what the bot has:

////Listen chat messages for cheers
client.on("cheer", function (channel, userstate, message) {
	console.log(" Cheers Accepted " + userstate.bits));
  if(userstate.bits >= config.cheerLimit){ //If users bit amount is not bigger that Hue trigger amount dont go in. You can change this in config.js

And this is the hue part of the script:

function hueLamp(alertType){

  if(status === 1){ // If there is an alert happening put the new alert to queue
      console.log("New job request (" + alertType + ") has been added to queue as there is an ongoing process");
    else {
      status = 1; // Lock alert to this one
      console.log("Active job: " + alertType);

      var alertName = ""; // Used later

      // If you want lower or higher bits to trigger alerts modify cheerOptions in config.js

      if(alertType >= config.cheerOptions.cheerTier1 && alertType < config.cheerOptions.cheerTier2){
        alertName = "bit_t1";
      else if(alertType >= config.cheerOptions.cheerTier2 && alertType < config.cheerOptions.cheerTier3){
        alertName = "bit_t2";
      else if(alertType >= config.cheerOptions.cheerTier3 && alertType < config.cheerOptions.cheerTier4){
        alertName = "bit_t3";
      else if(alertType >= config.cheerOptions.cheerTier4){
        alertName = "bit_t4";
        alertName = alertType;

      var intervalID = setInterval(function () { // Loops until there is no jobs in queue { changeColor(lampID, alertName); });
       if (++lampTimer >= colorEffects[alertName].blinkTime) {
  { changeColor(lampID, "normal"); });
           status = 0;
           console.log("Jobs Done! Checking queue for more jobs.");

           if(jobQueue.length > 0) {
             console.log("New Job!");

             var newAlertType = jobQueue[0];


             // Change timeBetweenAlerts in config to extend or shorten time between each job
             setTimeout(function(){ hueLamp(newAlertType);}, config.timeBetweenAlerts);
       }, colorEffects[alertName].blinkMS);

        lampTimer = 0;

what the different cheerTires is.

var cheerOptions = {
cheerTier1: 100,
cheerTier2: 1000,
cheerTier3: 5000,
cheerTier4: 10000
If someone can help me with this and find a soluiton it would be greate.

Each "alertName " is in another file where i store the colors! (example = alertName = “bit_t4”; )



What frame work are you using for your TwitchBot?

I use TMI.js for the twitch bot. Huejay for Philips Hue Ligths, and Chalk for “color console”.

At what point is your code failing? It looks like if hueLamp gets called it should have some console output regardless of the current state and alertType, so if it’s not getting that far throw in some logging to your cheer listener to see where it’s failing. Is config.cheerLimit defined? Is userstate.bits >= config.cheerLimit returning true when it should?

Well i did remake the “cheer” system to this and now it seems to work fine:

client.on(“cheer”, function (channel, userstate, bt, message) {
console.log(" Cheers Accepted " + userstate.bits));
if(userstate.bits = 100 && userstate.bits < 999){
bt = “t1”
}else if(userstate.bits = 1000 && userstate.bits < 4999){
bt = “t2”
}else if(userstate.bits = 5000 && userstate.bits < 9999){
bt = “t3”
}else if(userstate.bits = 10000){
bt = “t4”
hue.hueLamp(“bit_” + bt);

It did now add it into queue and start blinking as it should! :slight_smile:

Anyways thanks for your input :slight_smile:



A single equal sign is used to assign values to variables and a double equal sign is used for comparison.

Even though your code works you can completely simplify it by taking out the first half of your condition.

This example would accomplish the same task only if you wish to simplify and clean up some code.

client.on("cheer", function (channel, userstate, bt, message) {
  console.log(" Cheers Accepted " + userstate.bits));
  if(userstate.bits <= 999){
    bt = "t1"
  }else if(userstate.bits <= 4999){
    bt = "t2"
  }else if(userstate.bits <= 9999){
    bt = "t3"
    bt = "t4"
  hue.hueLamp("bit_" + bt);
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.