This is the companion repo to a tutorial on dev.to
This is a starter-kit for Twitch chat bot, if you wanna write one in Python. It utilizes the TwitchIO library and YAML files for storing secrets and config info.
It's pretty basic right now, but I'll be expanding on this in the near future. The larger, more complex Twitch bot is being developed HERE during Live-Streams on Twitch.
Should be quick & easy to get up and running but, ofc, if you ever have questions about the specifics, please feel free to ask me during streams or post an issue above.
- Python 3.6
- PIPENV ->
python -m pip install pipenv
- oauth token & client-id for a Twitch account for your bot
- Clone the repo, unzip it somewhere
- Open up a console window and navigate to the directory you unzipped it in
- Install requirements with
pipenv install
- Copy & rename
integrations-example.yaml
tointegrations.yaml
- Pop in all your secrets into the respective areas in
integrations.yaml
- Back to the console,
pipenv run python bot.py
to start the bot - Type
!test
in the chatroom to test the bot's working
You just installed a basic chat bot for Twitch! Have fun expanding the bot with more commands!! :D
Right now, you can only interact with the bot via the single command, !test
. You can create similar commands pretty easily, just copy the function and change out the function name decorator arguement...
@bot.command(name='likethis', aliases=['this'])
async def likethis(ctx):
await ctx.send(f'Asuh, @{ctx.author.name}!')
Test is out with !likethis
in chat! :D
There are 2 events that are used in the code right now.. on_ready
and on_event
.
This executes when the bot comes online, and will print out to the console.
@bot.event
async def event_ready():
print(f'Ready | {bot.nick}')
This function executes once per event (or message) sent. You can make it handle input from chat that aren't necesarily commands, and fun stuff like that.
@bot.event
async def event_message(message):
print(message.content)
await bot.handle_commands(message)
You can find more info in TwitchIO's official documentation.
NinjaBunny9000 - Author, Project Manager - Twitch // Twitter
Literally everyone that's helped even the smallest bit during streams. Thank you so much, y'all!