Discord bot to write message if Twitch stream goes online
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| .github/workflows | ||
| config | ||
| scripts | ||
| src | ||
| .gitignore | ||
| docker-compose.build.yml | ||
| docker-compose.yml | ||
| DOCKER.md | ||
| Dockerfile | ||
| LICENSE | ||
| README.md | ||
| renovate.json | ||
| requirements.txt | ||
DiscordStreamBot
Sends a Discord notification via webhook when a Twitch streamer goes live. No Discord bot token required — only webhook URLs.
Features
- Live stream notifications with thumbnail and title
- Multiple streamers monitored in a single batched API call
- Automatic Twitch token refresh with 401/429 handling
- Optional 1337 message via a separate webhook
- Debug log forwarding to Discord webhook
- Configurable poll interval
- No disk writes — thumbnails are kept in memory
Project Structure
src/
main.py — Entry point, logging setup
func/
models.py — StreamInfo dataclass
twitch.py — Twitch API client
webhook.py — Discord webhook sender
watcher.py — Main polling loop
config/
config.ini.dist — Configuration template
Dockerfile
docker-compose.yml — Pre-built image
docker-compose.build.yml — Local build
requirements.txt
Prerequisites
- Python 3.11+
- A Twitch application for
client_idandclient_secret - One or two Discord webhook URLs (channel settings → Integrations → Webhooks)
Configuration
Copy the template and fill in your values:
cp config/config.ini.dist config.ini
[DEFAULT]
LOG_LEVEL = INFO # DEBUG, INFO, WARNING, ERROR
poll_interval = 60 # Seconds between Twitch checks
[DISCORD]
webhook_url = # Webhook for stream notifications
leet_webhook_url = # Webhook for 1337 message (optional)
message = :red_circle: {user} ist live!
leet_user = # Discord user ID to mention at 13:37 (optional)
webhook_username = # Override webhook display name (optional)
webhook_avatar_url = # Override webhook avatar URL (optional)
[TWITCH]
client_id =
client_secret =
streams = streamer1,streamer2,streamer3
When LOG_LEVEL = DEBUG, all log output is also forwarded to webhook_url (batched per tick).
Running Locally
pip install -r requirements.txt
cp config/config.ini.dist config.ini
# edit config.ini
python src/main.py
Docker
Pre-built image
cp config/config.ini.dist config.ini
# edit config.ini
docker compose up -d
Local build
docker compose -f docker-compose.build.yml up -d --build
Rebuild from scratch
docker compose -f docker-compose.build.yml down --rmi all
docker compose -f docker-compose.build.yml up -d --build
Logs
docker compose logs -f
Getting Credentials
Twitch:
- Go to dev.twitch.tv/console
- Create a new application (category: anything, OAuth redirect:
http://localhost) - Copy Client ID and generate a Client Secret
Discord Webhook:
- Open channel settings → Integrations → Webhooks
- Create a new webhook and copy the URL
- Repeat for a second channel if you want a separate 1337 webhook
License
See LICENSE.