How to build a Twitch bot for free with 0 setup. (Part 1)

In fact, you’re not even going to write your own bot. You’re gonna use someone else’s bot.

John Rivs
5 min readMar 20, 2017

Alright, alright.. I lied a tiny bit. There’s less than a minute of setup. I said 0 setup because we’re not gonna do the “real world, production ready bot” type of setup.

If there’s something I hate about trying new libraries, techniques, environments or whatever, it’s not being able to start actually using and writing code with/for it. Just let me try it first. If I really taught you that way, we’d spend so much time just setting things up and getting you to the level where you would write actual commands. It’s soooo boring.

By the end of this tutorial, you’re gonna have a bot that:

  • Costs 0 dollars.
  • Doesn’t run on your own PC (so it will still work when you turn it off).
  • Can be shared with other people so they can contribute.
  • Can scale to a full blown bot at any point.
  • Requires 0 previous knowledge.
  • Can be written in any programing language.
  • Frees you from actually dealing with having a bot connecting to Twitch servers.

The secret

Not really a secret, but a shortcut. A really good one.

One day I needed a bot for someone’s channel and I had no idea how to build one. I googled around and found some programs with an interface and others that were more like IRC clients that offered some type of scripting language. “I need to have this program open all the time? That’s lame.” I abandoned the idea.

Some time later I was reading Nightbot’s documentation and came across an interesting feature. You can make Nightbot print in chat whatever’s returned from a URL. You might be thinking “So what? Why would I want to print a whole website in my chat?” but if you happen to know how to build websites, you probably see why this is so important. You would write the functionality in your favorite programing language and just return plain text.

And that’s what we’re gonna do. We’re gonna skip all the setup that a full featured bot requires and go straight into writing and toying with the functionalities you want your bot to have.

Edit: Nightbot is not the only bot that does that. There are many others, like Ankhbot.

The lab

Because we need a place to host our code.

The idea is basically writing a website with no design. It’s just text. In fact, the website doesn’t even know about a bot. You’ll be able to interact with it in your browser. Nightbot is gonna be the one visiting the URL of our website and printing in chat whatever it finds.

I know I said “requires 0 previous knowledge” and this tutorial is about building a bot with no setup at 0 cost. I am going to stand by these statements. You don’t need to know how to build websites and you don’t need to know how to buy a domain + web hosting and making the site available to the Internet.

We’re gonna use Runnable. This is just a playground. Useful for code examples, experiments.. It’s not meant for production ready stuff. The language of choice will be PHP. If you don’t know any language at all, cool. If you know PHP and you think it’s not the most ideal tool for this job, you’re right but you probably know why I’m choosing it in this tutorial. If you don’t, skip to the end of this tutorial. Also, remember that you can use any language, as long as you know how to get text printed on the screen.

Sign up, go back to the home page and click on the purple circle that has PHP written on it. After a few seconds you’re gonna see a new interface with a few things here and there. Ignore everything except these 2 things:

They give you a bit of code in the text editor that you see in the middle of the screen. Since this tutorial assumes no previous knowledge, I’ll explain the syntax. Feel free to skip these bits.

<?php says “Hey, I’m gonna write PHP in this file”. echo prints something on the screen. 'Hellow World' is a string (text) and it’s what echo is going to print. You can use single ( ‘ ) or double quotes ( “ ). ?> means “I finished writing PHP”, which can be left out if the file only contains PHP.

Let’s see what that looks like. Click on ‘Run’ and a new browser tab will open with the results of this code. It’s not really the raw results of the website we have going on, and since we want to give Nightbot plain text, click on the arrow you see on the top of this new tab to spawn yet another tab with an uglier URL where you really see the results of the website alone. It should say “Hello World”.

We will pretend we wrote all the functionality and that’s the output we want. Go to your chat and type this command to Nightbot !addcom !hello $(customapi URL) where URL is the ugly URL I mentioned above (the one without the purple box). If you type !hello in your chat:

Adding Nightbot to your chat, signing up to Runnable, getting the URL and adding the command. Takes less than a minute. That was the end of the setup. 1 minute between the start and you writing functionality.

PART 1 | PART 2 | PART 3

Why PHP?

It’s the easiest and cheapest to start out with.

My bot isn’t written in PHP on a code sandbox, but for the purposes of learning the first few steps, it’s the best.

  • It’s easy.
  • Requires no setup.
  • If you want to host this on a free domain + free web hosting you can just dump the code in a file and upload it to the internet. It has a low friction upgrade path.
  • Tons of documentation.

Overall, it’s a fantastic option to start writing commands in a minute.

Hey there! I’m John Rivs, web developer. After developing a Twitch bot for a while, I’ve decided to explain what’s the first step. My bot looks very differently today from what I show in this tutorial, but it explains almost exactly how my bot started.

Any questions? Leave a comment or hit me up on Twitter.