Twitch Twitter



Overview

Use Placeit's Twitch Banner Maker to level-up your streaming! Make all the assets you need fast and easy, simply choose a Twitch banner template and edit it. Connect your Twitch to hundreds of other services. Twitch is the world’s leading social video platform and community for gamers, video game culture, and the creative arts. Turn on Applets to grow your Twitch audience, and keep up with your favorite broadcasters' videos and livestreams. Watch live streams and the best highlights across Twitch categories like Just Chatting, Fortnite, Counter-Strike, League of Legends, and more. Twitch announced a major expansion of its misconduct policy today, allowing the streaming platform to take action against users who mistreat people on Twitter and Facebook.

Twitch Twitter Logo

Twitch offers an Internet Relay Chat (IRC) interface for chat functionality. Chatbots allow you to interact programmatically with a Twitch chat feed using IRC standards; the bot connects to the Twitch IRC network as a client to perform these actions. This guide presents an easy bot example to get you started, along with next steps for using chatbots and IRC.

Building the Bot

We’ll build a simple chatbot that responds in chat when someone types !dice. (This is known as a chatbot command.) When triggered, it randomly generates a number between 1-6. We run the fully-functioning chatbot on Glitch, and then show how you can alternatively run it locally on your computer. Here’s what the end result looks like: Audacity download mac free.

Get Environment Variables

To start, you’ll need three environment variables:

Twitch Twitter Card

VariableDescription
BOT_USERNAME

The account (username) that the chatbot uses to send chat messages. This can be your Twitch account. Alternately, many developers choose to create a second Twitch account for their bot, so it's clear from whom the messages originate.

CHANNEL_NAME

The Twitch channel name where you want to run the bot. Usually this is your main Twitch account.

OAUTH_TOKEN

The token to authenticate your chatbot with Twitch's servers. Generate this with https://twitchapps.com/tmi/ (a Twitch community-driven wrapper around the Twitch API), while logged in to your chatbot account. The token will be an alphanumeric string.

TwitchTwitch Twitter

Run the Chatbot on Glitch

Glitch lets you instantly create, edit, and host an app in the cloud. The code for this tutorial is live and can be accessed here. Simply put your credentials (the environment variables above) in the .env file and click Run.

Now that the bot is running and connected to the Twitch IRC network, we can interact with it. On twitch.tv/<CHANNEL_NAME>, type !dice. You’ll see a number from 1 to 6.

Run the Chatbot Locally

Twitch Twitter

If you prefer to build and run our bot example locally, follow these steps:

Twitch Twitter
  1. Download and install node.js if needed.
  2. On the command line, install tmi.js using the Node Package Manager.
    npm install tmi.js
  3. In bot.js below, replace the three environmental variables with the values obtained above.
  4. Run bot.js locally using node:
    node bot.js
  5. Now that the bot is running and connected to the Twitch IRC network, we can interact with it. On twitch.tv/<CHANNEL_NAME>, type !dice. You’ll see a number from 1 to 6.

bot.js

Twitch issues today

Next Steps

  • For more information about Twitch chatbots and IRC, see the Chatbots & IRC Guide.
  • To authenticate your chatbot in a production setting, we recommend you register your app (chatbot) and use the OAuth Authorization code flow. This enables you to authenticate programmatically. To learn more, see the Apps & Authentication Guide.
  • For help, reach out to @TwitchDev on Twitter or the Twitch chatbot forum.