A Twitch chatbot built with Python!
- Python 3.0+ installed on your machine
Linux/macOS:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Windows (Command Prompt):
python -m venv .venv
.venv\Scripts\activate.bat
pip install -r requirements.txt
Windows (PowerShell):
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
Create a .env
file in the project root directory with the following content:
# Your USER access token. Not APP access token.
# See instructions below for obtaining your user access token
TWITCH_OAUTH=
# Whatever nickname you want this chatbot to be
TWITCH_NICK=
# The Twitch channel you want this chatbot to join (MUST BE IN LOWERCASE)
TWITCH_CHANNEL=
When you have everything configured, simply run:
# In Linux/MacOS
python3 src/main.py
# In Windows
python src/main.py
- A Twitch account
- Go to https://dev.twitch.tv/console
- Click on "Register Your Application"
- Fill in the required information:
- Name: Choose a name for your application
- OAuth Redirect URLs: Set to
http://localhost
- Category: Select "Chat Bot"
- Client Type: Set to "Confidential"
- Click "Create"
- Click "Manage" for the application you just registered
- Copy your Client ID and generate a new Client Secret by clicking "New Secret"
We'll be following the "Authorization code grant flow" as described in the Twitch documentation.
Open a web browser and navigate to the following URL (replace [YOUR CLIENT ID HERE]
with your actual Client ID):
https://id.twitch.tv/oauth2/authorize?response_type=code&client_id=[YOUR CLIENT ID HERE]&redirect_uri=http://localhost&scope=chat%3Aread%20chat%3Aedit
After authorizing, you'll be redirected to a URL like:
http://localhost/?code=[YOUR AUTHORIZATION CODE]&...
Copy the authorization code value.
Send an HTTP POST request to the following endpoint (replace the placeholders with your actual values):
https://id.twitch.tv/oauth2/token?client_id=[YOUR CLIENT ID HERE]&client_secret=[YOUR CLIENT SECRET HERE]&code=[YOUR AUTHORIZATION CODE HERE]&grant_type=authorization_code&redirect_uri=http://localhost
You can use cURL, Postman, or any HTTP client to make this request.
On success, you'll receive a response like:
{
"access_token": "[YOUR ACCESS TOKEN]",
"expires_in": 14400,
"refresh_token": "[YOUR REFRESH TOKEN]",
"scope": ["chat:read", "chat:edit"],
"token_type": "bearer"
}
The access_token
value is what you need to set as TWITCH_OAUTH
in your .env
file.