๐ค A simple Discord bot that maintains a list of live Twitch streams in a Discord channel.
This readme was originally written for use with the Heroku free tier, however as Heroku has gotten rid of it, it's been repurposed for any generic server (I use Ubuntu).
Many bots simply post to a Discord channel when a streamer has gone live, the post gives you no indication as to whether the streamer is still live or what their status is, leading to the information in the channel becoming stale quickly.
This bot creates a card in the channel which updates throughout the duration of the streamer's stream, with uptime, viewcount, and a screenshot of their stream.
Once the streamer goes offline, the bot deletes the card, ensuring that the posts in your discord channel are all up-to-date and only referring to streamers who are live right now.
Multiple streamers can be added to the watch list, at your (or any server admin's) discretion.
- Maintains a real-time list of live streamers.
- No annoying @everyone mentions.
- Monitors Twitch streamers and posts on discord when they're live.
- Continously updates streamer card in the channel with uptime/game changes + screenshot.
- Deletes streamer card from channel when streamer goes offline.
- Discord commands to add/remove/list watched streamers (`add / `del / `list).
This is written for beginners, but it is expected that you at least know how to use basic unix shell commands.
Requirements
A server (this guide uses Ubuntu) where you have sudo.
Instructions
- Install Node
- Here's a decent guide on how to install node. I recommend using NVM (Option 3). This bot was built in node v18 so any LTS in v18 should be fine.
- Install a Node Process Manager
- I use PM2
npm install pm2@latest -g
- I use PM2
- Install PostgreSQL
sudo apt update
- Install PostgreSQL
sudo apt install postgresql postgresql-contrib
- Run PostgreSQL
sudo systemctl start postgresql.service
- Create a user
sudo -u postgres createuser --interactive
- Enter a name of your choice (the easiest is to use the same name as your unix username)
- Superuser: Y
- Set a psql password for the user
psql
- Enter and remember a password for the user.
\password
- Quit psql
\q
- Create a DB
sudo -u postgres createdb twitchmon
- Get the Bot
- Clone the repo into a folder on the server
git clone https://github.com/brofar/TwitchMonitor.git
- Rename
.env.sample
to.env
. - Set the
DATABASE_URL
topostgres://[username]:[password]@localhost:5432/twitchmon
.- Swap
[username]
with the psql username you created above. - Swap
[password]
with the psql password you set above.
- Swap
- Clone the repo into a folder on the server
- Get a Discord Token
- Generate a Discord bot token by following this guide.
- Copy the token into
DISCORD_BOT_TOKEN
in your.env
file.
- Get a Twitch Token
- Create a Twitch app on the Twitch Developer Console (When it asks, set the OAuth Redirect URL to
http://localhost
) - Copy the Twitch
Client ID
into theTWITCH_CLIENT_ID
in your.env
file. - Copy the Twitch
Client Secret
into theTWITCH_CLIENT_SECRET
in your.env
file.
- Create a Twitch app on the Twitch Developer Console (When it asks, set the OAuth Redirect URL to
- Start the Bot
cd
into the bot's directorypm2 start app.js --name twitch-monitor
- Invite the Bot to your Discord Server
- Go to
https://discord.com/api/oauth2/authorize?client_id=[BOT_CLIENT_ID]&permissions=8&scope=bot
- Swap
[BOT_CLIENT_ID]
in the URL above for your Discord app's client id. - If you want to lock down the announcement channel so nobody but the bot can post, ensure that the bot has permissions at minimum to Send Messages, Manage Messages, and Embed Links.
- Swap
- Start by issuing the
`channel
command (`channel #live-now
) to tell the bot where to post its messages. - Add streamers by issuing
`add streamer1 streamer2 etc etc
- Remove streamers by issuing
`del streamer1 streamer2 etc etc
- List followed streamers by issuing
`list
- Change the bot's command prefix using
`prefix !
(this would change the prefix from`
to!
)
- Go to
Assuming the default command prefix.
Sets the channel where the bot will announce streams.
Usage: `channel #live-now
Changes the bot's command prefix.
Usage: `prefix !
Adds a Twitch streamer to the watch list. You can specify multiple space-separated Twitch handles for quick addition.
Usage: `add user1 user2 user3
Removes a Twitch streamer from the watch list. You can specify multiple space-separated Twitch handles for quick removal.
Usage: `del user1 user2 user3
Lists all streamers the bot is currently watching.
Usage: `list