Twitch
How to make a Twitch chat bot
Build a Twitch chat bot with tmi.js: getting an OAuth token, handling commands and cooldowns, loyalty points, and generating the bot from a description with Devellix.
5 min read · Updated Jul 28, 2026
A Twitch chat bot connects to a channel's chat and responds to commands, runs giveaways, tracks loyalty points, or moderates. It joins chat like any user, using an OAuth token tied to a bot account.
The common stack is Node.js with tmi.js. This guide covers authentication, the shape of a bot, and how to generate one from a sentence so you can focus on the commands your community wants.
Step by step
- 1
Make a bot account and get an OAuth token
Create a separate Twitch account for the bot, then generate a chat OAuth token for it. The token lets your code connect to chat as that account. Keep it in an environment variable.
- 2
Understand a tmi.js bot
A tmi.js bot creates a client with the bot's identity and the channel to join, connects, and listens for message events. Each message handler checks the command and replies with client.say.
- 3
Add commands with cooldowns
A command like !dice checks a per-user cooldown so it cannot be spammed, does its work, and replies. Cooldowns and simple rate limits keep chat readable and are worth adding from the start.
- 4
Track points or watch time
A loyalty bot rewards active chatters on an interval and answers a !points command from a stored balance. Persisting balances to a file or database keeps them across restarts.
- 5
Generate the bot with Devellix
Describe the bot on Devellix and pick Twitch. It writes a tmi.js project with your commands and cooldowns, installs the dependencies, and bundles it. You add the bot's token and channel and run it.
What you can build
- A !dice or !roll command with a per-viewer cooldown
- A loyalty points bot that rewards watch time
- A giveaway bot that draws from active chatters
- A shoutout or !so command for raids
- A moderation bot that filters banned phrases