How to Connect Twitch Chat to Godot

In this tutorial, we are going to learn how to connect Twitch Chat to a Godot project. Luckily there’s an addon in the Godot Asset Library that does the heavy lifting for us.

I recommend following this tutorial with a new, empty Godot project. The addon generates scenes to help you make sure it’s working. Once you do get it working, then it will be easier to merge it into an existing project.

Download the GIFT Addon

Go to the Godot Asset Library and find the "GIFT – Godot IRC For Twitch" addon by MennoMax. Download and install it.

Alternatively you can download it here:
https://github.com/MennoMax/gift

The addon will generate scenes and scripts for us to help us get it working.

Run the project. Godot will have us select a main scene.

Select "Node.tscn".

In the Output window, we will see some helpful things printed out.

This output is basically telling us that the addon successfully connected to Twitch, sent invalid credentials, and then disconnected.

Create an Auth File

We will define our Twitch channel credentials within it’s own, seperate "auth" file.

Why are we doing this? Well, we could put the credentials in the Godot script, but then if we were to upload our project online, to GitHub for example, then other users could see and use our credentials.

Our credentials are meant to be kept secret. So we will keep them in a seperate file.

First open the project files in your operating system’s file browser. You can easily do this from within Godot.

Create a new file there simply named "auth", without a file extension. Open the "auth" file in your text editor of choice. On Windows you can use the built-in program, Notepad.

Register Your Application

Navigate to

https://dev.twitch.tv/console/apps

Sign in with your Twitch account if you need to.

Click on "Register Your Application".

Enter a name for your application on Twitch. The name must be unique.

Under the OAuth Redirect URLs, add

https://twitchapps.com/tokengen/

Select a Category and click Create.

Copy the Client ID. We will need it to generate an OAuth token.

Generate OAuth Token

Navigate to

https://twitchapps.com/tmi/

Paste the Client ID and click Connect.

Copy the OAuth token. We will put this in our "auth" file.

Fill in Credentials

Open the "auth" file. If you are on Windows you can open it in Notepad.

This is the format of the "auth" file:

Nickname
OAuth token
Twitch channel name

My brief testing showed that the nickname is not used, so it doesn’t matter what you put there. I just used my Twitch channel name as the nickname.

The "oauth:" portion of the OAuth token is required.

The Twitch channel name should be self-explanatory. Use all lowercase characters.

Connected to Twitch

Try running the Godot project. If everything is working, the output should look something more like this.

When you type something in and click Send, it should also appear in your Twitch chat.

I will note that connecting to Twitch chat seems to randomly fail every 1/10 times or so. When this happens you simply need to restart the game.

For a production release, I would recommend checking if the connection was successful and reattempting to connect, if not.

Leave a Reply

Your email address will not be published.

Scroll to top