A Python script for Twitch Chat interaction with almost any game.
- Python https://www.python.org/downloads/ (tested with 3.10)
- Download Autohotkey from https://www.autohotkey.com/ and provide the .exe path to line 5 of the script.
- Install ahk through pip - https://pypi.org/project/ahk/
- Get your Twitch oauth key from https://twitchapps.com/tmi/ (DO NOT SHARE THIS!), and paste the key on line 10 between the parentheses.
ahk = AHK(executable_path='PATH')
Line 10 - Add the oauth code that was generated from https://twitchapps.com/tmi/ here (include "oauth:" that is apart of the generated code).
PASS = "OAUTH_CODE"
BOT = "BOT_NAME"
CHANNEL = "CHANNEL_NAME"
OWNER = "ACCOUNT_NAME"
Game controls are handled by condition checks(if chat sends "up", AHK will read "up" and pass the command to the game).
# For an "UP" Press:
if "up" == message.lower():
ahk.key_press('up')
message = ""
# For a "DOWN" Press:
if "down" == message.lower():
ahk.key_press('down')
message = ""
py twitchchatplays.py
:tmi.twitch.tv 001 :Welcome, GLHF!
:tmi.twitch.tv 002 :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 :This server is rather new
:tmi.twitch.tv 004 :-
:tmi.twitch.tv 005 :-
:tmi.twitch.tv 006 :You are in a maze of twisty passages, all alike.
:tmi.twitch.tv 007 :>
:tmi.twitch.tv 001 :Welcome, GLHF!
:tmi.twitch.tv 002 :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 :This server is rather new
:tmi.twitch.tv 004 :-
:tmi.twitch.tv 005 :-
:tmi.twitch.tv 006 :You are in a maze of twisty passages, all alike.
:tmi.twitch.tv 007 :>
:name![email protected] JOIN #name
:name.tmi.twitch.tv 008 name = #name :name
:name.tmi.twitch.tv 009 name #name :End of /NAMES list
:name![email protected] JOIN #name
:name.tmi.twitch.tv 001 name = #name :name
:name.tmi.twitch.tv 002 name #name :End of /NAMES list
BOT has joined name's Channel!
tmi.twitch.tv CAP * ACK : twitch.tv/tags
-- Twitch chat messages will show up here. --