Skip to main content
Version: 2.0.0-beta.3

Token setup

The Twitch API is, unfortunately, designed in a way that makes using a bot like this a little more involved than it ought to be. This section will help you deal with the API requirements. It probably seems a little daunting if you're not familiar with what the "Authorization Code Grant Flow" is, but we've done most of the worrying about that for you—there's only a little bit left that you need to do: register an application with Twitch and set up your initial tokens.

Registering an application

Per Twitch requirements, you'll need to have a verified email and 2FA enabled for this to work, so make sure you've done that first. Once you have, go to the Twitch developer console and log in with your Twitch account. From there:

  1. Open the "Applications" tab and click "Register your Application"
  2. Pick a name for your bot's application. You'll be the only person to ever see this name, so don't think too hard about it!
  3. Set the OAuth Redirect URL to http://localhost:3000
  4. Set the category to "chatbot"
  5. Prove you aren't a bot (with the "I'm not a robot" checkbox)
  6. Click "Create".

You should be redirected back to the Applications tab, where your application should be listed now. If you click "Manage" on the application, you'll be taken to a new page. Note down the Client ID listed here, and click the "New Secret" button to generate and note down a Client Secret.

Generating an initial token

Now you need to use that Client ID and Client Secret to generate an access token and a refresh token. This will require installing the Twitch CLI, so follow the instructions there; on Linux, the manual install option is probably easiest, and on Windows it's probably easiest just to install Scoop and use it (this will require using Powershell instead of Command Prompt).

Once you have the Twitch CLI installed:

  1. Make sure you're logged into Twitch with the account you want to use as your bot.
    • If you're using a dedicated bot account, make sure the bot is a moderator in your chat first! This is required to get the list of online users in your chat, which the bot needs in order to know who's online and who's offline.
  2. In your terminal (or Powershell) window, run the command twitch token -u -s "chat:read chat:edit moderator:read:chatters".
  3. When prompted, enter your Client ID and Client Secret from earlier. You'll need these again when you're configuring the bot, so don't get rid of them!
    • Pasting into a terminal window usually requires right clicking instead of pressing Control+V; Control+V has a different meaning inside a terminal window.
  4. Authorize your application to access your account in your browser, when it opens an authorization page.
  5. The Twitch CLI will output a User Access Token and a Refresh Token. Note these down too!

Creating tokens.json

Download the sample tokens.json file from our Git repository, and save it in your settings folder as tokens.json. Replace {INITIAL_ACCESS_TOKEN} (including the braces) with the User Access Token, and {INITIAL_REFRESH_TOKEN} with the Refresh Token.

tip

Do not include the braces; your tokens should be enclosed in quotation marks but not braces.