Sending and Receiving Chat Messages

To send a chat message to a channel’s chat room, use a PRIVMSG message.

PRIVMSG #<channel name> :This is a sample message

Your chat messages can also include emoticons. To include emoticons, use the name of the emote. The names are case sensitive. Don’t include colons around the name (e.g., :bleedPurple:). If Twitch recognizes the name, Twitch converts the name to the emote before writing the chat message to the chat room. For examples of emoticons, see Emotes.

PRIVMSG #<channel name> :HeyGuys <3 PartyTime

NOTE: If you send too many messages in rapid succession, The Twitch IRC server will close the connection.

For information about including chat commands (e.g., /clear) in a message, see Twitch IRC Chat Commands.

Replying to a chat message

If your bot wants to reply to a chat message, it needs to get the chat message’s ID. This means your bot must request the tags capability. With tags enabled, the PRIVMSG message that the Twitch IRC server sends your bot will include the id tag, which identifies the chat message.

@badge-info=;badges=broadcaster/1;client-nonce=459e3142897c7a22b7d275178f2259e0;color=#0000FF;display-name=lovingt3s;emote-only=1;emotes=62835:0-10;first-msg=0;flags=;id=885196de-cb67-427a-baa8-82f9b0fcd05f;mod=0;room-id=713936733;subscriber=0;tmi-sent-ts=1643904084794;turbo=0;user-id=713936733;user-type= :lovingt3s! PRIVMSG #lovingt3s :bleedPurple

To reply to the above chat message, your bot sends the following PRIVMSG message and includes the reply-parent-msg-id tag, which identifies the chat message you’re replying to.

@reply-parent-msg-id=885196de-cb67-427a-baa8-82f9b0fcd05f PRIVMSG #lovingt3s :absolutely!

And this is what the reply looks like in the chat room.

Screenshot of reply message

Receiving chat messages

When a user enters a message in the channel’s chat room, the Twitch IRC server sends your bot a PRIVMSG message.

:foo! PRIVMSG #bar :bleedPurple

In the above message, the first part of the message identifies who wrote the message in the chat room. In this case, foo wrote the message.

The second part of the message identifies the type of message (command) and the name of the channel (chat room). In this case, the command is PRIVMSG and the message came from the bar channel’s chat room.

The third part of the message is the chat message that the user posted in the chat room. In this case, the message text contains the bleedPurple emote.

Note that your bot will not receive PRIVMSG messages for chat messages that it writes to the chat room. Instead, it receives a USERSTATE message, but only if you request the tags and commands capabilities. The display-name tag contains the bot’s name. The message does not include the chat message the bot sent.

@badge-info=;badges=moderator/1;color=#FF4500;display-name=mybot;emote-sets=0,300374282;mod=1;subscriber=0;user-type=mod USERSTATE #bar

If your bot requested the tags capability, the following example shows what the PRIVMSG message looks like when it includes tags. Learn more.

@badge-info=;badges=broadcaster/1;client-nonce=28e05b1c83f1e916ca1710c44b014515;color=#0000FF;display-name=foofoo;emotes=62835:0-10;first-msg=0;flags=;id=f80a19d6-e35a-4273-82d0-cd87f614e767;mod=0;room-id=713936733;subscriber=0;tmi-sent-ts=1642696567751;turbo=0;user-id=713936733;user-type= :foofoo! PRIVMSG #bar :bleedPurple

Convention for bot commands

If your bot accepts commands, the convention for third-party commands is to use an exclamation point (e.g., !dice). Using the forward slash or dot (e.g., /ban or .ban) is reserved for Twitch commands.

Next steps

Get familiar with: