A Node.js Discord bot that monitors selected Twitch streamers and posts rich “going live” embeds in your Discord server.
- ⚙️ Built with Node.js 18+, discord.js v14 and the Twitch API
- 💾 Uses MariaDB/MySQL for persistent configuration and history
- 🛰️ Fully driven by slash commands (no legacy prefixes)
- 🧠 One message per stream – the bot edits a single embed while the stream is live instead of spamming new messages
-
🎯 Per-server Twitch streamer tracking
-
📝 Custom notification messages:
- server-level template
- per-streamer overrides
-
🧵 Optional role mentions (e.g.
@live,@twitch, etc.) -
🔍 Optional title keyword filter via
.env -
🔁 Smart live message updates:
- title
- game
- viewer count
- thumbnail with cache-busting
-
🗄️ MariaDB/MySQL storage for:
- guild configuration
- tracked streamers
- stream history
-
🧩 Slash command deployment script included
- Requirements
- Platform Credentials
- Discord Bot Permissions & Invite
- Quick Setup
- Environment Variables
- Database
- Slash Commands
- Message Variables
- Title Keyword Filter
- How It Works
- npm Scripts
- Troubleshooting
- Security Notes
- Project Structure
- License
-
Node.js 18+ and npm
-
MariaDB or MySQL
-
Discord application with:
- bot token
- application/client ID
-
Twitch application with:
- client ID
- client secret
-
Go to Discord Developer Portal
https://discord.com/developers/applications -
Create a new Application and add a Bot.
-
Note down:
- Application ID (client ID)
- Bot Token
-
Go to Twitch Developer Console
https://dev.twitch.tv/console/apps -
Create a new application.
-
Note down:
- Client ID
- Client Secret
botapplications.commands(required for slash commands)
Send MessagesEmbed LinksRead Message History
Optional but useful:
Manage Messages
https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=81968&scope=bot%20applications.commands
81968 corresponds to Send Messages + Embed Links + Read Message History.
-
Clone the repo and install dependencies
git clone https://github.com/<your-username>/discord-twitch-notifier.git cd discord-twitch-notifier npm install
-
Create the
.envfile in the project root (⚠️ do not commit this file – see Environment Variables) -
Initialize the database (one time)
mysql -u <user> -p < database_full.sql
-
Deploy slash commands
npm run deploy
Run this again whenever you add or change slash commands.
-
Start the bot
npm start
Create a file named .env in the project root with:
DISCORD_TOKEN=your_discord_bot_token
DISCORD_CLIENT_ID=your_discord_app_client_id
TWITCH_CLIENT_ID=your_twitch_client_id
TWITCH_CLIENT_SECRET=your_twitch_client_secret
DB_HOST=localhost
DB_PORT=3306
DB_NAME=discord_bot
DB_USER=root
DB_PASSWORD=your_db_password
# How often the bot polls Twitch (milliseconds)
CHECK_INTERVAL=60000
# (Optional) word/phrase that must appear in the stream title
# Leave empty to notify for every live stream
STREAM_TITLE_KEYWORD=You can also commit a .env.example file (same keys, fake values) to document the configuration without exposing secrets.
The file database_full.sql contains the full schema, including tables for:
- per-guild configuration (channel, role, message templates, etc.)
- tracked streamers
- stream history
Apply it with:
mysql -u <user> -p < database_full.sqlUse the same script for new installs or to align an existing database schema.
Main commands exposed by the bot:
| Command | Description |
|---|---|
/add-streamer |
Add a streamer, with optional custom message |
/edit-streamer |
Edit or reset a streamer-specific message |
/remove-streamer |
Remove a monitored streamer |
/list-streamers |
List all streamers configured for this guild |
/set-channel |
Set the channel used for notifications |
/set-role |
Set or clear the role to be mentioned in notifications |
/set-message |
Set the server-level message template |
/config |
Show the current configuration |
/test-notification |
Send a test notification |
/help |
Show a quick reference of all commands |
Typically only users with permissions like Manage Server should be allowed to run configuration commands.
Both server-level and streamer-level templates support placeholders:
{streamer}→ Twitch display name{game}→ current game{title}→ stream title{url}→ Twitch stream URL@role→ replaced with the configured role mention (set via/set-role, if any)
Server-level template:
@role {streamer} is now live on Twitch playing {game}!
{title}
{url}
Streamer-level override:
@role 🚨 {streamer} just went live: "{title}" → {url}
If a streamer-level message exists, it takes precedence over the server-level template.
To reduce noise, you can filter notifications based on the stream title using STREAM_TITLE_KEYWORD in .env.
- Empty → all streams from tracked streamers trigger notifications
- Non-empty → notifications are sent only if the title contains that word/phrase (case-insensitive)
Examples:
STREAM_TITLE_KEYWORD=speedrun
STREAM_TITLE_KEYWORD=duo queue
STREAM_TITLE_KEYWORD=Restart the bot after changing this variable.
-
Every
CHECK_INTERVALmilliseconds, the bot:- reads the list of configured streamers from the database
- queries the Twitch API for their live status
-
For each streamer:
-
if the streamer is live and passes the (optional) title filter:
-
if there is no active message stored for the current live session:
- the bot sends a new embed in the configured channel and stores the message ID
-
if there is an active message:
-
the bot edits the existing message, updating:
- title
- game
- viewer count
- thumbnail (with cache-busting)
-
-
-
when the stream ends:
- the bot stops updating that message until the next live session
-
-
All guild and streamer configuration is stored and read from MariaDB/MySQL.
Result: users get one live embed per stream that stays fresh, instead of a wall of repeated messages. 🔁
| Script | Description |
|---|---|
npm start |
Start the bot in production mode |
npm run dev |
Start the bot with node --watch |
npm run deploy |
Register/update global slash commands |
Quick checks if something doesn’t work:
-
Bot doesn’t start
- Check console logs.
- Verify
.envvalues (Discord token, DB credentials, Twitch keys).
-
No notifications in Discord
-
Make sure you set a notification channel with
/set-channel. -
Verify the bot has:
Send MessagesEmbed Links
-
Run
/configto check the current channel, role and templates. -
Try
/test-notification. -
If
STREAM_TITLE_KEYWORDis set, confirm that the stream title actually contains it.
-
-
Database errors
- Verify DB host/port/user/password/name in
.env. - Confirm that
database_full.sqlhas been imported into the correct database.
- Verify DB host/port/user/password/name in
-
Never commit:
.env- logs or dump files containing tokens/passwords
-
Discord and Twitch tokens, plus DB credentials, should live only in environment variables.
-
Before making the repo public, double-check:
- no
.envor backup copies are tracked - no DB dumps or sensitive debug files are included
- no
Indicative project layout:
src/
commands/
add-streamer.js
edit-streamer.js
remove-streamer.js
list-streamers.js
set-channel.js
set-role.js
set-message.js
config.js
test-notification.js
help.js
database.js
deploy-commands.js
index.js
monitor.js
twitch.js
database_full.sql
package.json
README.md
File names may vary slightly, but the overall structure is similar.
This project is licensed under the MIT License.
See the LICENSE file for full details.