Steps
Create a Discord webhook
In Discord, open the channel settings, then Integrations, then Webhooks, create one and press Copy Webhook URL. New to webhooks? See Discord webhooks for beginners.
Register a free Twitch app
Sign in at
dev.twitch.tv/console(two-factor authentication must be on), choose Register Your Application, usehttp://localhostas the OAuth redirect URL and pick a category. Open the app, copy the Client ID and create a Client Secret. These give an app access token, which is all you need to read who is live; no viewer login or bot account.Save the script
Copy the script below into
twitch_live_to_discord.py. It uses only Python's standard library. It asks Twitch which of your channels are live (up to 100 in one request), posts one message per new stream, and remembers the stream id so the same stream is never announced twice.Set your channels and keys
Put these in a
.envfile next to the script, then check the output without posting anything withpython3 twitch_live_to_discord.py --dry-run:TWITCH_CLIENT_ID=your_client_id TWITCH_CLIENT_SECRET=your_client_secret CHANNELS=shroud,pokimane,your_friend DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/XXX/YYYCHANNELSare the login names from the channel address (twitch.tv/name), comma-separated.Run it every few minutes
Each run is one token request and one API call, then the script exits. Every 2 to 5 minutes is plenty:
*/3 * * * * cd /path/to/twitch-alert && set -a && . ./.env && set +a && /usr/bin/python3 twitch_live_to_discord.py >> run.log 2>&1No always-on computer? See how to run a Python script on a schedule (cron, Task Scheduler or GitHub Actions). On GitHub Actions, cache or commit
twitch_live_state.jsonbetween runs, or each run will re-announce streams that are already live.
The script
#!/usr/bin/env python3
"""Post to a Discord webhook when Twitch channels go live. Standard library only."""
import json, os, sys, urllib.parse, urllib.request
ID_URL = os.environ.get("TWITCH_ID_URL", "https://id.twitch.tv/oauth2/token")
API_URL = os.environ.get("TWITCH_API_URL", "https://api.twitch.tv/helix/streams")
CLIENT_ID = os.environ["TWITCH_CLIENT_ID"]
CLIENT_SECRET = os.environ["TWITCH_CLIENT_SECRET"]
CHANNELS = [c.strip().lower() for c in os.environ["CHANNELS"].split(",") if c.strip()][:100]
WEBHOOK = os.environ.get("DISCORD_WEBHOOK_URL", "")
STATE = os.environ.get("STATE_FILE", "twitch_live_state.json")
DRY = "--dry-run" in sys.argv
def call(url, data=None, headers={}):
req = urllib.request.Request(url, data=data, headers={"User-Agent": "twitch-live-alert/1.0", **headers})
with urllib.request.urlopen(req, timeout=20) as r:
body = r.read()
return json.loads(body) if body else {}
token = call(ID_URL, urllib.parse.urlencode({"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET,
"grant_type": "client_credentials"}).encode())["access_token"]
query = urllib.parse.urlencode([("user_login", c) for c in CHANNELS])
live = call(f"{API_URL}?{query}", headers={"Client-Id": CLIENT_ID, "Authorization": f"Bearer {token}"})["data"]
seen = json.load(open(STATE)) if os.path.exists(STATE) else {}
now = {s["user_login"]: s["id"] for s in live}
for s in live:
if seen.get(s["user_login"]) == s["id"]:
continue # already announced this stream
msg = f"🔴 **{s['user_name']}** is live: {s['title']}\nPlaying {s['game_name'] or 'something'} · https://twitch.tv/{s['user_login']}"
if DRY or not WEBHOOK:
print(msg)
else:
call(WEBHOOK, json.dumps({"content": msg, "allowed_mentions": {"parse": []}}).encode(),
{"Content-Type": "application/json"})
if not DRY:
json.dump(now, open(STATE, "w"))
What we saw when we tested it (18 Oct 2026)
- Against a local stand-in for the Twitch and Discord APIs: the first run posted one message for the live channel and saved its stream id; the second run, same stream, posted nothing; when a second channel went live only that one was posted; when everyone went offline the state emptied; and a new stream from the first channel was announced again. Five runs, three messages, no duplicates.
- A stream title containing
@everyonewas posted as plain text and pinged nobody, because the script sendsallowed_mentionswith an empty list. - The real
https://api.twitch.tv/helix/streamsendpoint answers401without a token, which is why the script fetches an app access token first.
Customise it
- Ping a role: start the message with
<@&ROLE_ID>and changeallowed_mentionsto{"roles": ["ROLE_ID"]}, so only that role is pinged and stream titles still can't ping everyone. - Telegram or Slack instead: replace the webhook call with Telegram's
sendMessage(see RSS to Telegram for getting a bot token and chat id) or a Slack incoming webhook, which takes the same{"text": ...}style JSON. - Only some games: skip streams whose
game_nameisn't in your list before posting.
Prefer n8n?
A Schedule Trigger, an HTTP Request node that POSTs to https://id.twitch.tv/oauth2/token with grant_type=client_credentials, a second HTTP Request to https://api.twitch.tv/helix/streams?user_login=NAME with the Client-Id and Authorization: Bearer headers, Remove Duplicates across executions on the stream id, and a Discord node (webhook) do the same job.
Good to know
- Why not a bot? Bots like MEE6 or Streamcord work, but you have to invite them with server permissions and rely on their uptime. A webhook can only post to the one channel you chose.
- Tokens: app access tokens last about two months; the script simply asks for a fresh one each run, so it never has to handle expiry.
- Short drops: if a streamer's connection drops and Twitch starts a new stream, it gets a new id and is announced again.
Skip the setup: free download
The Twitch live alert agent does all of this. It's tested, MIT-licensed, and comes as an n8n workflow plus a Python script.
Get the free Twitch live alert agent → Or have us build yours →
FAQ
Can Discord notify me when a Twitch streamer goes live without a bot?
Yes. A channel webhook can post the message, and a small script that asks Twitch's API who is live every few minutes decides when. Nothing has to stay online between runs.
Do I need a Twitch API key?
Yes, a free Client ID and Client Secret from dev.twitch.tv/console. You don't need to log in as a viewer or create a bot account.
How many streamers can I follow?
Up to 100 channels per request. For more, run a second copy with its own CHANNELS and STATE_FILE.
Will it spam the channel?
No. It announces each stream once, using Twitch's stream id, and stays quiet until the streamer goes offline and starts a new stream.
Is it free?
Yes. Twitch's API and Discord webhooks cost nothing, and the script is yours to change.
Related guides
- Twitch live notifications in Telegram: get a message when a streamer goes live
- Discord bot without coding: do you even need a bot? Webhook vs builder vs your own
- 13 Discord webhook automation ideas you can set up without a bot
- Send GitHub releases, issues and pull requests to Discord (no bot)
- n8n 413 Request Entity Too Large? Payload limits tested
New guides
- GitHub release notifications in Slack (any public repo, stable releases only)
- Send RSS feeds to Slack with a keyword filter (free, incoming webhook)
- Forward emails to a Slack channel (Gmail, Outlook, any IMAP), free with an incoming webhook
- n8n Google Sheets Trigger not working: not firing, activation errors and fixes