TwitchIrcChannel Node (Deprecated)
DeprecatedWarning: This node relies entirely on the TwitchIRC system, which Twitch plans to deprecate and remove. Avoid using TwitchIrcChannel for new development. Migrate existing usage to EventSub-based solutions like TwitchChat and TwitchEventListener. Using this node may result in broken functionality in the future.
The TwitchIrcChannel node provides a focused way to interact with a single, specific Twitch channel when using the underlying TwitchIRC connection manager. It's primarily intended for scenarios where your application needs to connect to and manage multiple Twitch channels concurrently.
Overview
While the main TwitchIRC node handles the overall connection and receives events for all joined channels, TwitchIrcChannel acts as a filter and interface for just one of those channels.
When added to the scene and configured with a channel_name:
- It finds the main
TwitchIRCinstance (via the assignedTwitchService). - It registers itself with the
TwitchIRCnode usingirc.add_channel(self). This tells theTwitchIRCnode to potentially JOIN this channel if it hasn't already. - It listens to the global signals from
TwitchIRC(received_privmsg,received_roomstate,received_userstate). - When an event arrives from
TwitchIRC, this node checks if the event's channel matches its ownchannel_name. - If the channel matches, it emits its own, more specific signal (e.g.,
message_receivedinstead ofreceived_privmsg). - It provides a
chat()method that automatically targets its specific channel. - It tracks whether the
ROOMSTATEfor its channel has been received, indicating a successful join (joinedproperty,has_joinedsignal).
Prerequisites
- Functional
TwitchIRC: You must have a correctly configured and connectedTwitchIRCnode available, typically managed via a parentTwitchServicenode. - Add the Node: Add a
TwitchIrcChannelnode to your scene. - Assign Dependencies:
Twitch Service: Assign the parentTwitchServiceinstance that contains the activeTwitchIRCnode.Channel Name: Crucially, set this property in the Inspector to the name of the Twitch channel (e.g., "your_channel_name", without#) that this node should represent.
Configuration (Inspector Properties)
Twitch Service(TwitchService): Required. A reference to theTwitchServicenode that holds the activeTwitchIRCinstance.Channel Name(StringName): Required. The login name of the Twitch channel this node instance will manage and filter events for (e.g., "kani_dev"). Setting this property triggers registration with the parentTwitchIRC.
Signals
These signals are emitted only for events related to this node's specific channel_name:
message_received(from_user: String, message: String, tags: TwitchTags.Message)- Emitted when a
PRIVMSGarrives from the parentTwitchIRCthat matches this node'schannel_name. tags: A processedTwitchTags.Messageobject, which attempts to load emote/badge sprites using theTwitchService'sTwitchMediaLoader.
- Emitted when a
user_state_received(tags: TwitchTags.Userstate)- Emitted when a
USERSTATEmessage arrives fromTwitchIRCfor this channel, providing the bot's current state (badges, color, etc.) in this specific channel.
- Emitted when a
room_state_received(tags: TwitchTags.Roomstate)- Emitted when a
ROOMSTATEmessage arrives fromTwitchIRCfor this channel, indicating current chat settings (emote-only, etc.). This signal also triggers thehas_joinedsignal the first time it's received.
- Emitted when a
has_joined()- Emitted once when the
ROOMSTATEfor this channel is first received, indicating the bot has successfully joined and received initial state information.
- Emitted once when the
has_left()- Emitted when the node is notified of leaving the channel (typically when removed from the scene tree or when
irc.leave_channelis called).
- Emitted when the node is notified of leaving the channel (typically when removed from the scene tree or when
Methods
chat(message: String) -> void- Sends a chat message specifically to this node's
channel_namevia the parentTwitchIRCnode'schatmethod. - It implicitly waits (
await is_joined()) until thehas_joinedsignal has been emitted before attempting to send the message, ensuring the bot is actually in the channel.
- Sends a chat message specifically to this node's
is_joined() -> void- An asynchronous utility function. If the channel hasn't received its initial
ROOMSTATEyet (joinedis false), it waits for thehas_joinedsignal to be emitted. Useful for ensuring actions are only taken after joining is confirmed. Useawaitwhen calling.
- An asynchronous utility function. If the channel hasn't received its initial
leave() -> void- Internal method called when the channel is being parted from. It resets the internal
joinedstate and emits thehas_leftsignal. Usually triggered automatically when the node exits the tree orirc.remove_channel(self)is called.
- Internal method called when the channel is being parted from. It resets the internal
Usage Example
Scenario: Connecting to two channels ("channel_one", "channel_two") and handling their chat separately.
- Set up
TwitchServicewithTwitchIRCas usual. - Add two
TwitchIrcChannelnodes as children (e.g.,IrcChannelOne,IrcChannelTwo). - In the Inspector for
IrcChannelOne:- Assign the
TwitchServicenode to theTwitch Serviceproperty. - Set
Channel Nameto"channel_one".
- Assign the
- In the Inspector for
IrcChannelTwo:- Assign the
TwitchServicenode to theTwitch Serviceproperty. - Set
Channel Nameto"channel_two".
- Assign the
extends Node
# References to the specific channel nodes
@onready var channel_one_handler: TwitchIrcChannel = $IrcChannelOne
@onready var channel_two_handler: TwitchIrcChannel = $IrcChannelTwo
func _ready() -> void:
# Ensure TwitchService (and thus TwitchIRC) is set up first
# await TwitchService.setup() # Assuming TwitchService is accessible
channel_one_handler.message_received.connect(_on_channel_one_message)
channel_one_handler.has_joined.connect(_on_channel_joined.bind(&"Channel One"))
channel_two_handler.message_received.connect(_on_channel_two_message)
channel_two_handler.has_joined.connect(_on_channel_joined.bind(&"Channel Two"))
func _on_channel_joined(channel_identifier: StringName) -> void:
print("%s successfully joined!" % channel_identifier)
# Maybe send a welcome message after joining
if channel_identifier == &"Channel One":
channel_one_handler.chat("Bot connected to Channel One!")
elif channel_identifier == &"Channel Two":
channel_two_handler.chat("Bot connected to Channel Two!")
func _on_channel_one_message(from_user: String, message: String, tags: TwitchTags.Message) -> void:
print("[Channel One] %s: %s" % [from_user, message])
# Handle message specific to channel one
func _on_channel_two_message(from_user: String, message: String, tags: TwitchTags.Message) -> void:
print("[Channel Two] %s: %s" % [from_user, message])
# Handle message specific to channel two