How to execute a .bat file with a command (with a cooldown by user if possible) on the twitch chat


I have different .bat associated with google home, which allows me to change my led’s color. If I execute the .batch, it changes the color, so I need to create different commands to execute that .batch from the chat.

Thanks you.


The Chat Guide in the docs includes an example of how to create a bot that connects to chat and performs a function when there is a command

All you would need to do is change the command to whatever you want it to be, and have it execute your .bat file. If you want a cooldown, just simply have a boolean variable that flips when the command is used, and then after a set period of time flips back, and then simple check that variable when the command is used.


That’s cool, but when I try to open the JavaScript in cmd with “node bot.js” it gives me this error:

username: lyricalstring_lightsbot,

ReferenceError: lyricalstring_lightsbot is not defined
at Object. (C:\Users\alexm\Desktop\bot.js:6:15)
e[90m at Module._compile (internal/modules/cjs/loader.js:1151:30)e[39m
e[90m at Object.Module._extensions…js (internal/modules/cjs/loader.js:1171:10)e[39m
e[90m at Module.load (internal/modules/cjs/loader.js:1000:32)e[39m
e[90m at Function.Module._load (internal/modules/cjs/loader.js:899:14)e[39m
e[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)e[39m
e[90m at internal/main/run_main_module.js:17:47e[39m

Could you help me?


Additionally to my reply, I removed the <> symbols of the 3 variables because if not it said "SyntaxError: Unexpected token ‘<’ "


The values that are wrapped in < > in the example are for you to replace with what your username/OAuth token is.

The reason you are getting a not defined error with your username is because it’s a string, you need to put it in single or double quotes, eg 'lyricalstring_lightsbot' or "lyricalstring_lightsbot". Same for the OAuth token used as the password, it’s a string so has to be in quotes, or a variable that you’ve already defined.

If you are inexperienced with Javascript/NodeJS I recommend either connecting to chat using a library in a language you’re more familiar with, or reading through some introduction to NodeJS guides to understand the basics.