This is a python project to send a Discord webhook with a self-updating webhook
when a specified streamer goes live on Twitch.
Checks and updates exactly once every half minute.
The motivation behind this project is that requiring discord.js or the twitch api library is too much in my opinion.
The same goes for having to invite a bot just for this purpose.
The project does 7 API calls, including the really basic authentication in twitch's case.
Table of contents
All options to run this require environment variables. You can see them in this file.
STREAMER_NAME
This is the easiest one. It holds the all lowercase username of the streamer you wish to notify for.
Examples: kaicenat
, xqc
, esl_csgo
, steve_the_streamer
, etc.
DISCORD_WEBHOOK_URL
Your Discord webhook URL. Acquiring one requires the Manage Webhooks
permission on Discord.
- Hover a channel in the server you wish to notify in.
- Click
Edit Channel
(the cog icon on the right). - Go to
Integrations
. - Click
Create Webhook
orEdit Webhooks
, depending on if the channel already has webhooks. - Click
New Webhook
(Skip if using an existing one). - Click the webhook in the overview, it will expand.
- You can give it a name, but the app by default sets it itself.
- Click
Copy Webhook URL
.
Now you have your webhook URL in your clipboard and can paste it into your .env file.
TWITCH_CLIENT_ID and TWITCH_CLIENT_SECRET
The bread and butter variables of this application. These are needed to query the Twitch API.
Please refer to the official documentation on how to register an app.
As part of the documentation steps you will generate a client ID and client secret.
Use those in the .env file.
The first option - and the option I use - is to run the project's docker image.
It has the benefit of being able to run multiple instances at the same time.
Note: There is a limit by Twitch for how many access tokens you can have active at the same time for the same twitch client.
You have two paths you can take here:
- You may use this project's docker image in the container registry.
- You may also fork the project and host it in your own registry.
- You may build the image yourself using the Dockerfile.
You can read up on how to install docker on the official website.
The pipeline builds your image into your GitHub project's docker registry at
ghcr.io/<YOUR USERNAME>/discord-twitch-live-notifier:main
.
In my case that's ghcr.io/gadsee/discord-twitch-live-notifier:main
.
You can use that to pull your image:
docker image pull ghcr.io/<YOUR USERNAME>/discord-twitch-live-notifier:main
Note: If you use a private repository,you will have to docker login ghcr.io
with your username and a GitHub personal access token as password first.
Then run the image. Take note to adjust the path at --env-file
.
docker run \
--name discord-twitch-live-notifier \
--env-file /path/to/your/env-file/.env \
-d \
ghcr.io/gadsee/discord-twitch-live-notifier:main
Your OS may treat line breaks in commands differently, please adjust accordingly. The above is tested on linux/debian.
To stop and remove the container (app), run
docker stop discord-twitch-live-notifier
docker rm discord-twitch-live-notifier
You may also build the image yourself locally:
docker build -f Dockerfile -t some_image_tag --build-arg .
And then run the image with the same instructions as above.
The second option to run the project is to run it locally. You may install the dependencies through pip, however it is recommended to install them with the project default, poetry.
- Python 3.11.2
Clone the repository:
git clone https://github.com/Gadsee/Discord-Twitch-Live-Notifier.git
Install poetry (taken from the official documentation):
Debian-based linux distributions:
sudo apt-get install python3-pip curl
curl -sSL https://install.python-poetry.org | python3 -
Windows:
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
poetry env use 3.11.2
poetry install
Replace source .env
with your OS' appropriate way of loading environment variables.
poetry shell
source .env
python -m app.main
This project uses multiple linting plugins to ensure code formatting is consistent.
black .
is opinionated but uncompromising code formatting.flake8
enforces style guide, i.E. PEP8.isort .
sorts imports.
Additionally, there is a pre-commit hook you can install to fix trailing whitespace, end of file and some yaml issues.
pre-commit install
You may also use it to quickly check through everything without needing to commit:
pre-commit run --all-files
Depending on your shell compatibility with poetry, you may have to prefix all of the above commands with poetry run
.