TwitchBot Node
The TwitchBot node provides a way to send chat messages as a designated bot account, separate from your main authenticated user. This is the mechanism required to have messages appear in Twitch chat with the official Bot badge next to the username.
Overview
This node is a self-contained system for a bot's chat functionality. It does not use the main TwitchAPI instance of your project. Instead, it creates its own internal TwitchAuth and TwitchAPI instances to:
- Manage a dedicated
OAuthTokenfor your bot account. - Handle the authentication flow for that bot token.
- Send chat messages using the bot's identity (
sender) to a target channel (receiver).
The primary purpose is to fulfill Twitch's requirements for sending messages that receive the "Bot" chat badge.
Scope and Permission Requirements
Using this node involves a more complex permission setup than standard chat messages. All of the following conditions must be met:
- Client Secret: Your
OAuthSettingresource must have the Client Secret filled in. The bot's authentication flow requires it. - Bot Account (
sender): The Twitch user account designated as your bot must grant your application theuser:botscope. - Broadcaster Account (
receiver): The broadcaster of the channel where the bot will speak must either:- Grant your application the
channel:botscope. - OR make your bot account a moderator in their channel.
- Grant your application the
Without these specific permissions, attempts to send messages via this node will fail.
Prerequisites
- Add the Node: Add a
TwitchBotnode to your scene. - Assign
OAuthSetting: Assign your mainOAuthSettingresource to theOauth Settingproperty. Ensure it contains your Client Secret. - Create and Assign
Bot Token:- Create a new, separate
OAuthTokenresource file. This token will be used exclusively by the bot. - Assign this new resource to the
Bot Tokenproperty. - You must ensure this token is authorized by the Twitch account you intend to use as your bot. This might involve a separate, one-time authorization process for that account.
- Create a new, separate
- Assign
SenderandReceiver: AssignTwitchUserresources for both the bot account (Sender) and the target channel's broadcaster (Receiver).
Configuration (Inspector Properties)
Oauth Setting(OAuthSetting): Required. Your primaryOAuthSettingresource. TheTwitchBotnode duplicates this but requires theClient Secretto be present.Bot Token(OAuthToken): Required. A dedicatedOAuthTokenresource for the bot user. This token will be authenticated and managed independently of your application's main user token.Sender(TwitchUser): Required. TheTwitchUserresource representing the bot account that will send the messages.Receiver(TwitchUser): Recommended. TheTwitchUserresource representing the broadcaster of the channel where messages will be sent. If not set, it defaults to theSender.- Note: For the "Bot" badge to appear, the
SenderandReceivermust be different users.
- Note: For the "Bot" badge to appear, the
Signals
This node does not introduce new public signals for general use.
Methods
send_message(message: String, reply_parent_message_id: String = "", for_source_only = true, broadcaster: TwitchUser = null) -> void- Sends a chat message as the configured bot user.
message: The text content of the message to send.reply_parent_message_id: Optional. The ID of a message to reply to.broadcaster: Optional. ATwitchUserobject for the target channel. Ifnull, it defaults to theReceiverproperty, which in turn defaults to theSenderproperty.- Note: This method is
async. You can call it withawaitto wait until the message was sent. It will automatically handle authorizing thebot_tokenif it's not already authenticated.
Usage Example
extends Node
# Assuming TwitchBot node is configured in the scene
@onready var twitch_bot: TwitchBot = $TwitchBot
func _ready():
# Example: send a message after a short delay
await get_tree().create_timer(5.0).timeout
send_bot_greeting()
func send_bot_greeting():
print("Sending greeting from bot '%s' to channel '%s'" % [twitch_bot.sender.display_name, twitch_bot.receiver.display_name])
await twitch_bot.send_message("Hello! I am a bot user powered by Twitcher.")
print("Bot message sent (or at least attempted).")Considerations
- Complex Permissions: The
user:botandchannel:botscope requirements are strict. This feature is advanced and requires careful setup on the Twitch developer side for multiple user accounts. - Client Secret is Mandatory: The bot's authentication flow relies on the Client Credentials grant, which requires your application's Client Secret.
- Bot Badge: The "Bot" badge will only appear if the sender and the target broadcaster (channel) are different Twitch users.