This is a Twitch bot that is a companion to my soundboard project. You do not need to use the soundboard project to use this bot. However, this bot works by default with the file name conventions established in that project.
In order to run this script, you must have NodeJS installed. Additionally, this script utilizes VLC Media Player.
This bot will monitor a specified Twitch channel's chat for specific commands from Twitch channel rewards and StreamElements rewards.
Then it will play a sound or random sound from a specified /sounds
folder through an audio device of your choosing.
This is designed to work with virtual audio cables, where you can route your mic and soundboard through a single device which can then be used on your stream. Your setup doesn't have to be the exact same, as this script will allow you to specify a device to play the sound on. However, if you need more info on setting up virtual audio cables and a mixer, this article I wrote for my soundboard is a good place to start.
If you are familiar with Github, you can simply clone this repository. Otherwise, you can download this zip file and extract to a folder on your computer.
Open up a terminal or command prompt and navigate to the folder where you extracted the repository. Then run the following command:
npm install
Open ./src/index.ts
in order to configure the bot. The code is heavily commented to try and
make it easy to update. You can look for the lines START CONFIGURATION
and END CONFIGURATION
for guidance
on what you should be updating.
-
Run VLC Media Player.
-
Go to Tools -> Preferences.
-
Click on the Audio tab. Click this tab first or else you won't get a list of sound devices!
-
Under Show settings section at the bottom left of the window, choose All.
-
Under the Audio category on the left, expand Output Modules and select WaveOut.
-
Under the Select Audio Device dropdown box, look for your desired output device. You need to copy EXACTLY what it shows in the dropdown box. Write or type down exactly what is in here.
Your file names should follow this structure:
file name [category1, category2].mp3.
The script will check each file name and take the comma-separated category names from with the []
square brackets. You can add as many categories as you want, allowing this file to be included
when you tell the bot to pick a random sound from a category.
After adding a chat command to StreamElements, you can incorporate a behavior into the bot by
adding the command to the streamElementsRewards
option of the configuration.
Example:
'!command_name': 'filename.mp3'
You can link sounds to commands in three ways:
- Single File:
'!command_name': 'filename.mp3'
- Multiple Files:
'!command_name': ['filename1.mp3', 'filename2.mp3']
- Random Sound From Category:
'!command_name': ''
In order to choose a random sound from a category, you use an empty string next to the command name. Just below the main configuration, you will need to add the following for each command:
soundLibrary.addSoundsFromCategory({
command: '!hello',
category: 'hello',
aliases: ['!hi'],
})
- Add the Twitch Channel Point Reward, being sure to select User Response Required. This is the only way the bot is able to determine if a Twitch Channel Point Reward was redeemed.
- With the bot running (see the Testing the Bot section below), redeem the reward in your chat. Look for Channel reward id: in your terminal or command prompt, and copy the ID.
- In the configuration, update
twitchChannelPointsRewards
with a sound category and the ID.
Example, playing a random sound from the insult
category:
insult: YOUR_REWARD_ID_COPIED_FROM_TERMINAL
In your terminal or command prompt, navigate to the folder where you extracted the repository. Then run the following command:
npm run dev
You can now go to your channel and start redeemeing rewards to test and ensure the bot responds accordingly!
Once you have tested the bot and everything looks good, you can build the bot and run it. In your terminal or command prompt, navigate to the folder where you extracted the repository. Then run the following command:
npm run build
This will create a ./dist
folder with the compiled bot. You can then run the bot via your terminal or command prompt by navigating to the folder where you extracted the repository, then running the following command:
node dist/index.js
Inlcuded in the root of this project is a file called start.bat
. Update the script to point to
your compiled bot. Then you can run this bat file, or create a shortcut to it on your desktop, to quickly start the bot.
Example start.bat
:
START cmd /k "cd D:\Coding\projects\soundboard-twitch-bot\dist & node index.js"