Your project
Twitch chat in your Godot game
Ask Flockbay for Twitch chat and it writes it into your game: one autoload that reads the streamer’s chat, and the chat play in your own scripts, such as a vote on the next room, commands that spawn enemies, or viewers joining the game. It signs in with your own Twitch app and talks to Twitch only, with no server in between. By default the stream shows votes and counts, never chat text.
What Flockbay writes
Say what chat should do in your game: “let my Twitch chat vote on the next room”, “let viewers spawn hazards in front of me”, or “a viewer types !join and gets a unit with their name over it”. Flockbay works out the commands from your game.
It writes one autoload, StreamChat, at res://stream_chat/stream_chat.gd. StreamChat reads chat with Twitch’s EventSub over WebSocket and signs the streamer in with Twitch’s device code flow. It turns each message into votes and commands and sends them to your game through signals. Your game’s side, the vote panel, the commands and the joins, goes in your own scripts.
Both are ordinary GDScript files in your project: read them and change them like the rest of your code. Nothing of Flockbay’s runs in the game, and StreamChat talks to Twitch and nothing else.
Flockbay also adds a Twitch section to your game’s Settings, a test scene, two test actions in Tune, and a draft privacy notice. All of it is described below.
Register your Twitch app
The game signs in with a Twitch app of your own, one per game. Until it has one, everything runs on simulated chat, so you can build and test first.
- Open dev.twitch.tv/console and log in. Twitch asks you to turn on two-factor authentication first if it is off.
- Choose Register Your Application. Name it after your game, set OAuth Redirect URLs to http://localhost (the device code flow does not use it), Category to Game Integration and Client Type to Public, then choose Create.
- Open Manage on the new app and copy its Client ID.
- Give the Client ID to Flockbay. It goes in your project settings as twitch/client_id.
A Client ID is public by Twitch’s own definition, and a Public client has no secret, so nothing in the project needs hiding. Twitch does not allow one Client ID to be shared between apps, so each of your games gets its own.
Connect on stream
- In your game, open Settings, then Twitch, and turn on Twitch chat. Channel can stay blank to read your own channel.
- Press Connect. The game shows a code.
- Go to twitch.tv/activate and enter the code, ideally with the code off stream. The status line then reads Connected as your Twitch name.
- Type in your chat. Votes and commands reach the game within a moment.
The sign-in is saved on the computer, encrypted, and the game checks it with Twitch when it starts and every hour, as Twitch requires. After about a month without use, Twitch asks for a new code. Disconnect signs out and revokes the sign-in.
Votes, commands and joins
A vote takes !1, !2 and so on, !vote 2, a bare 2, or a keyword from the option’s name, such as !fire. Each viewer has one vote, and the latest one counts. A vote lasts at least 20 seconds, because viewers see the stream 5 to 30 seconds late. A tie goes to the option that reached the top count first, and a vote with no ballots is left to the game.
Every command a chatter can use to change the game, such as a spawn or a modifier, goes through a per-viewer cooldown and a shared limit, and the game caps how many chat-spawned things are alive at once. A refused command is dropped quietly: nothing is posted in chat.
Moderators and the streamer can type !pause and !resume to stop and restart chat play, and the streamer has a key for the same thing. The game says which key.
The limits, the vote length and the cooldowns are exported values under Twitch chat, so you can tune them in Tune and the Inspector.
What reaches your stream
You answer for what appears on your stream, so the defaults keep chat text off it. The screen shows the game’s own option names and live counts. A viewer’s name shows only after they join with the game’s join command, and Hide names in the game’s Twitch settings turns names off.
Chat text shows only if you ask for it, and each line waits 10 seconds first. When a moderator deletes a message, times out or bans a viewer, or clears chat, that text, name or vote leaves the screen at once. If the game shows names or text, Shield Mode turns it back to votes only.
Nothing from chat is saved: names and messages last until the game closes.
Test before you go live
Nothing needs a live channel to test. In a debug build, Simulated chat in the game’s Twitch settings stands in for chat: made-up viewers vote while a vote is open.
While the game runs, Tune has two test actions: Send test chat message, with a viewer name and text, and Send 30 test votes. Both run only in a debug build, so the game you export never runs them.
Flockbay also writes a test scene, res://tests/stream_chat_test.tscn, that feeds the game chat messages, a ban and a deleted message, and checks what the game did. It runs headless, with no window and no network.
Publish the privacy notice
Twitch’s Developer Agreement asks every game that uses its chat for a public privacy notice. Flockbay drafts one at res://stream_chat/PRIVACY-NOTICE.md. It says what the game reads from Twitch, that nothing is kept after the session, what the game posts, if anything, and how to disconnect.
Add your contact, then publish it on your game’s website or store page. Once it has an address, the Privacy button in the game’s Twitch settings opens it.
Posting in chat
By default the game never posts in chat. Ask Flockbay if you want it to, for example to answer a command. It then posts as the streamer, only in reply to something, and never repeats a viewer’s message or name. Twitch asks for permission to post the next time the streamer connects.
A small Made with Flockbay credit can go in the vote panel if you ask for one. The streamer can turn it off with Hide credit in the game’s Twitch settings.
Reading chat without signing in
Twitch chat can also be read with no Twitch app and no sign-in, through the anonymous chat login that Twitch’s own web chat uses. Flockbay adds it only if you ask, as a second choice in the game’s Twitch settings. Twitch has never documented that login, so if Twitch closes it, a game that uses it stops reading chat until it is updated. It only reads: it never posts.
Playtests, exports and other platforms
In Flockbay Playtest the game reaches Twitch but cannot open a browser, so the streamer types twitch.tv/activate and the code. The sign-in lasts that session.
The game you export needs twitch/client_id set. A web export runs the same code and signs in each session.
Bits and Channel Points can trigger effects in the game, never a bet or anything of monetary value, and no part of the game depends on following the channel.
Ask Flockbay for YouTube Live chat and it builds it on your own Google Cloud project, which has a quota of 10,000 units a day. Kick needs a server, because its sign-in takes a client secret and its chat events arrive by webhook. TikTok has no official API for live comments.
Related
- Multiplayer: test rooms and Steam
- Exporting your game
- Twitch: Chat and chatbots
- Twitch: Handling WebSocket events
- Twitch: Device code grant flow
- Twitch Developer Agreement
- Godot: WebSocketPeer
- Security: where your project lives and what leaves your machine
- How to use Steam Broadcasting for your game
- Build with your Claude plan
- How to grow your game's Discord server
- How to market your game on Reddit, and on every other channel
