Here is the exact Python script using the requests library to check if a Twitch stream is live, alongside a Node.js (JavaScript) alternative. Before running either script, make sure you have registered an application on the Twitch Developer Portal to get your Client ID and Client Secret. Option 1: Python Code Block This script handles the required two-step process: it first requests a temporary access token from Twitch, and then uses that token to check the channel's status. python import requests # 1. Configuration (Replace with your own credentials) CLIENT_ID = 'your_client_id_here' CLIENT_SECRET = 'your_client_secret_here' CHANNEL_NAME = 'ninja' # Target twitch channel username def check_twitch_live(client_id, client_secret, channel): # 2. Get the OAuth Access Token token_url = 'https://twitch.tv' token_params = { 'client_id': client_id, 'client_secret': client_secret, 'grant_type': 'client_credentials' } try: token_response = requests.post(token_url, params=token_params) token_response.raise_for_status() token_data = token_response.json() access_token = token_data['access_token'] except requests.exceptions.RequestException as e: return f"Failed to retrieve access token: {e}" # 3. Setup Headers for the Get Streams Endpoint streams_url = 'https://twitch.tv' headers = { 'Client-ID': client_id, 'Authorization': f'Bearer {access_token}' } streams_params = { 'user_login': channel } # 4. Check the Channel Status try: response = requests.get(streams_url, headers=headers, params=streams_params) response.raise_for_status() data = response.json().get('data', []) if len(data) > 0: stream_info = data[0] return { "is_live": True, "title": stream_info.get("title"), "game": stream_info.get("game_name"), "viewer_count": stream_info.get("viewer_count") } else: return {"is_live": False} except requests.exceptions.RequestException as e: return f"API Query Failed: {e}" # Run the function status = check_twitch_live(CLIENT_ID, CLIENT_SECRET, CHANNEL_NAME) print(status) Use code with caution. Option 2: Node.js Code Block (JavaScript) If you are building a modern web application or backend API, this native fetch pattern is the standard approach. javascript const CLIENT_ID = 'your_client_id_here'; const CLIENT_SECRET = 'your_client_secret_here'; const CHANNEL_NAME = 'ninja'; async function checkTwitchLive() { try { // 1. Fetch OAuth token const tokenResponse = await fetch(`https://twitch.tv{CLIENT_ID}&client_secret=${CLIENT_SECRET}&grant_type=client_credentials`, { method: 'POST' }); const tokenData = await tokenResponse.json(); const accessToken = tokenData.access_token; // 2. Query the Twitch Helix API const streamsResponse = await fetch(`https://twitch.tv{CHANNEL_NAME}`, { method: 'GET', headers: { 'Client-ID': CLIENT_ID, 'Authorization': `Bearer ${accessToken}` } }); const streamsData = await streamsResponse.json(); // 3. Evaluate live status if (streamsData.data && streamsData.data.length > 0) { const stream = streamsData.data[0]; console.log({ isLive: true, title: stream.title, game: stream.game_name, viewers: stream.viewer_count }); } else { console.log({ isLive: false }); } } catch (error) { console.error('Error fetching Twitch status:', error); } } checkTwitchLive(); Use code with caution. Understanding the API Response Output • Offline Result: The code will evaluate to {"is_live": false}. • Live Result: If the channel is actively broadcasting, the API responds with a populated array giving you metadata you can map into your frontend or notification system:json { "is_live": true, "title": "🔴 24 HOUR MARATHON EVENT!", "game": "Just Chatting", "viewer_count": 14200 } Use code with caution. If you want to move forward, tell me: • Do you need help setting up environment variables (.env) to securely hide your API secrets? • Are you planning to make a Discord Webhook connection to auto-post messages when it returns true? I can provide the extra configuration layers based on your goals.