Bot can't send chat messages containing whitespace

The chat bot I’ve developed seems to work exactly as anticipated. It can send/receive chat messages, as well as send/receive whispers without any issue. But whenever any message being sent to the channel contains whitespace, it doesn’t appear in chat & the server doesn’t respond with anything. I’m just left completely in the dark. This doesn’t happen if I whisper the message, only when I attempt to send it to chat. Receiving messages which contain whitespace are also not an issue.

I’ve taken a very thorough examination of my code, and it doesn’t appear to be the problem, since I can send whitespace messages as a whisper, and can send an identical, non-whitespace version of that message to the channel. It only fails when it’s a whitespace version sent to the channel.

Any ideas?

What kind of whitespace? How are you sending the messages?

Spaces made via the spacebar. For example…

  • WS Version: “Test Message” (only works as a whisper, or receiving from chat)
  • Non-WS Version: “TestMessage” (works 100%)
  • WS Version:
    PRIVMSG #botchannel Test Message
  • Non-WS:
    PRIVMSG #botchannel TestMessage

Have you tried it like this: PRIVMSG #botchannel :Test Message


That worked, thanks! This stuff really should be documented better.
The docs say nothing about case-sensitive channel names, nor that the exclusion of a colon works for sending messages as long as there is no whitespace involved. These sort of things are important to know for devs just starting to get to know about twitch IRC.

I guess it is confusing when it sometimes works without it (not sure if that is intended), but it is in all the examples like that and I guess it’s not specificially mentioned because it’s part of the IRC standard.

Not to troll or anything, but the Twitch docs do indicate:

PRIVMSG: Sending a message

PRIVMSG #channel **:**Message to send

As you can see, the colon is required before the message and tduva is right, that is the IRC standard. When I was working on rewriting an IRC library for my bot I stepped back, captured all the messages from Twitch and did some light reading on the IRC standard as well as the Twitch documents for their specific deviations from the standard.

That deviation can sometimes cause heartburn for sure.

The case sensitivity on channel names is a Twitch thing. They really should just lowercase() the channel names, but they don’t.
The colon is IRC standard, however. And the effect of only getting the first word is a pretty classic bug effect when trying to interact with IRC servers.

I’d also like to add that to fully conform, you also need to terminate your IRC messages with an explicit trailing \r\n. (CR-LF)

[quote=“IllusionaryOne, post:7, topic:8683, full:false”]
Not to troll or anything, but the Twitch docs do indicate:

PRIVMSG: Sending a message
PRIVMSG #channel **:**Message to send

As you can see, the colon is required before the message[/quote]
Where in the twitch docs does it say it’s required? Because it isn’t, or at least not for channel messages without whitespace. You can even send whispers containing whitespace without the use of a colon.

That’s part of the issue. They claim to closely follow the standard RFC, but I keep hearing differently from other posters who state that there are too many deviations. Possibly even more than what they have documented. The docs feel less like “instead of X we do Y”, and more like “here are a few possible things that you can do/expect”. From what I’ve read & experimented with, not everything is as black & white as most other organization’s docs. I seriously feel it is lacking, and I know that I’m not alone in that opinion.

Yeah, I already figured that. I kinda saw it as common sense, since the majority of my previous network-related programming projects do the same thing. It’s usually either that, or a null terminator. Thanks!

Nowhere in the docs does it say use privmsg without the colon. The fact that it somewhat works without it could be considered a coincidence or even a bug. All lowercase channel name is mentioned on JOIN notes, but it could be mentioned on privmsg too I guess.

1 Like

Well it doesn’t make sense to PRIVMSG a room you have not JOINed and JOIN specifies lowercase. So it sounds logical to me.

The thing with a whisper is that it’s interpreted slightly as a server command. So it’s parsed differently which is why it works without the colon. (I imagine)

Really if you have having issues. You may want to consider using an existing IRC library or twitch specific library. Rather than rolling your own

It is because the IRC spec sort of says you can. It specifies that parameters to a command can start with a colon to allow spaces or not have a colon, but not allow spaces. Parameters are space separated. However there’s only 1 parameter allowed in PRIVMSG, so doing PRVIMSG #channel Test Message\r\n will result in you specifying two parameters. That isn’t a valid PRIVMSG anymore. If you use the colon on the parameter, further spaces get eaten as part of the parameter rather than becoming a delimiter.

You can do PRIVMSG #channel TestMessage\r\n and you’ve got one parameter following the no-space syntax.
You can do PRIVMSG #channel :Test Message\r\n and you’ve got one parameter of Test Message

Now, correct me if I’m wrong, but whispers aren’t formally documented. You’re lucky they work if you actually sent it without the colon.

Note: I’d always send it with a colon. The non-colon case is pretty rare, really, as everyone in normal IRC world just blindly adds colon everyone to be safe and to make it easier.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.