Have to reload Twitch channel to see messages sent via IRC socket

I am using python to connect to my channel and (among other things in the future) send messages to the channel. What I have works, except I cannot see the message until I reload the page in the browser. Upon reload, I see the message. A friend of mine observed the same behavior. Chat in my channel and others works as expected otherwise - it has something to do with how I am sending it in python.

I use send_message(irc, message) to encode and then send the message and I call it in join_chat(). Here is the full code:

from dotenv import load_dotenv
import os
import socket



irc.connect((SERVER, PORT))
irc.send((  "PASS " + OAUTH + "\n" +
            "NICK " + BOT_NAME + "\n" +
            "JOIN #" + CHANNEL + "\n").encode())

def join_chat():
    loaded = False
    while not loaded:
        # saves 1024 bytes at a time
        readbuffer_join = irc.recv(1024).decode()
        # split into lines and discard last line (empty)
        for line in readbuffer_join.split('\n')[:-1]:
            loaded = check_load_complete(line)

def check_load_complete(line):
    if 'End of /NAMES list' not in line: return False
    print(f'{BOT_NAME} joined {CHANNEL}\'s channel')
    send_message(irc, f'{BOT_NAME} joined the channel')
    return True

def send_message(irc, message):
    message = (f'PRIVMSG #{CHANNEL} :{message}\n').encode()


I am following this guide on youtube: https://www.youtube.com/watch?v=MSFgLOc6Xnc

I have tried as many variations of message as I could think of. breaking the encoding to a separate line., using \r instead of or in addition to \n, getting rid of \n, string concat instead of fstrings, etc. Of course the message getting sent must be valid because I do see it after reload, so maybe something is wrong with the state of irc when I call send_message(irc, "some message")?

It’s an edge case front end display bug. It occurs in quiet chats. I can’t always replicate the issue. It’s just weird.

Thanks Barry that actually explains a lot. It must be relatively new - the guide I’m watching doesn’t have the same issue (~2017). I wonder what constitutes “quiet”.

Twitch’s UI and frontend has changed a lot since 2017

Seems so. Thanks for the info. I take it I would not see different behavior if I send a message via the Twitch API?

How would you send chat via the API?

The only way to read/write to Twitch Chat (aka TMI) is via IRC over Sockets or IRC over IRC.

The only other chat thing is the “Send Chat as a Twitch Extension”

I did a quick search to answer that same question (can you send a message via the API) and evidently I came to the wrong conclusion! I guess I wouldn’t.

I marked your initial response as the solution. Thanks for the clarification on my follow-up questions.

I found my problem - it’s not related to a quiet chat but I will report my findings because there is something I find odd about it. Also, another symptom I observed is that I could not read anything from the socket buffer.

My NICK in my python script included a capital. When I changed it to lowercase it worked. What I find odd is that it seems new accounts can be made with capital letters but it seems they get converted to all lowercase. That’s how I noticed - I made a new account with capitals, saw it got converted, then used lowercase. Then I thought to use lowercase on my old account and it worked.

Twitch chat rooms are all lowercase

You don’t

JOIN #BarryCarlyon


PRIVMSG #BarryCarlyon :words and stuff


JOIN #barrycarlyon
PRIVMSG #barrycarlyon :words and stuff

But you are sending to #BarryCarlyon then the messages shouldn’t of been seen at all, even with a refresh.

I guess it gets converted somewhere to lowercase.

I am joining a channel with:

irc.send((  "PASS " + OAUTH + "\n" +

            "NICK " + BOT_NAME + "\n" +

            "JOIN #" + "Nonethewiserer" + "\n").encode()) 

I’m getting the buffer and printing it as shown in my original post. Which shows:

:tmi.twitch.tv 001 nonethewiserer :Welcome, GLHF!
:tmi.twitch.tv 002 nonethewiserer :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 nonethewiserer :This server is rather new
:tmi.twitch.tv 004 nonethewiserer :-
:tmi.twitch.tv 375 nonethewiserer :-
:tmi.twitch.tv 372 nonethewiserer :You are in a maze of twisty passages, all alike.
:tmi.twitch.tv 376 nonethewiserer :>
:nonethewiserer!nonethewiserer@nonethewiserer.tmi.twitch.tv JOIN #Nonethewiserer
:nonethewiserer.tmi.twitch.tv 353 nonethewiserer = #Nonethewiserer :nonethewiserer
:nonethewiserer.tmi.twitch.tv 366 nonethewiserer #Nonethewiserer :End of /NAMES list
Jukebox joined Nonethewiserer’s channel

Not sure if this is expected or not. I don’t quite understand how I provide Nonethewiserer and see JOIN #Nonethewiserer on the fourth to last line of the output, when - like you say - it should be lowercase. I’m not looking for an explanation (you’ve been very helpful already) - I’m just sharing this information because I can’t square it. Maybe it makes perfect sense though. Anyways, now I cannot reproduce the successful message sent after refresh after retesting.

Twitch will still let you join a “invalid” channel, you just won’t get any inbound chat messages/sent by others

You need to join nonethewiserer

Rooms are idenfitied by the login not the display name

So you load


And check the login

Awesome, that make sense!

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