Bot can login and pong but can't do anything else

I’m in the early stages of making a custom bot in Python. I’m using the basic Python socket module.

I establish a connection (i’ve tried both irc.chat.twitch.tv and irc.twitch.tv), send my oauth, send my nick. I receive a successful connection response (“maze of twisty passages”) with the correct username. After this, i get no response from the server except pings.

I’ve tried joining channels, sending messages, enabling membership, etcetc, but nothing. I know the connection is alive because I get pings. It seems that the server recognizes the pongs I send back because I stay connected until I stop sending pongs.

Here is the terminal input/output for the bot:

~ $ python ircclient.py






$send password
[INFO] (Thread-1  ) <--| PASS oauth:yj**********************************k7t

$send username
[INFO] (Thread-1  ) <--| NICK mibaz

[INFO] (Thread-2  ) -->| :tmi.twitch.tv 001 mibaz :Welcome, GLHF!
:tmi.twitch.tv 002 mibaz :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 mibaz :This server is rather new
:tmi.twitch.tv 004 mibaz :-
:tmi.twitch.tv 375 mibaz :-
:tmi.twitch.tv 372 mibaz :You are in a maze of twisty passages, all alike.
:tmi.twitch.tv 376 mibaz :>

$join:summit1g
[INFO] (Thread-1  ) <--| JOIN #summit1g
$enable membership
[INFO] (Thread-1  ) <--| CAP REQ :twitch.tv/membership
join:summit1g
[INFO] (Thread-1  ) <--| PART #summit1g
JOIN #summit1g
$msg:yoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
[INFO] (Thread-1  ) <--| PRIVMSG #summit1g :yoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
$send:anything?
[INFO] (Thread-1  ) <--| anything?
[INFO] (Thread-2  ) -->| PING :tmi.twitch.tv

$pong:tmi.twitch.tv
[INFO] (Thread-1  ) <--| PONG :tmi.twitch.tv

[INFO] (Thread-2  ) -->| PING :tmi.twitch.tv

$pong:tmi.twitch.tv
[INFO] (Thread-1  ) <--| PONG :tmi.twitch.tv

[INFO] (Thread-2  ) -->| PING :tmi.twitch.tv

$pong:tmi.twitch.tv
[INFO] (Thread-1  ) <--| PONG :tmi.twitch.tv

[INFO] (Thread-2  ) -->| PING :tmi.twitch.tv

[INFO] (Thread-2  ) -->| PING :tmi.twitch.tv

[INFO] (Thread-2  ) connection aborted
$quit
[INFO] (MainThread) closed

~$ 

I know it’s kind of an unlucky time for me to start because of the server migration, but I was hoping someone could help me see what I’m doing wrong. I’m probably missing something simple.

I’ll provide source code at anyone’s request. If anyone has any ideas, please let me know.

Thanks!

EDIT:
The channel I tried to join was extremely active. I tried the cap req right after connecting and I got no response.

EDIT:
Code on github: https://github.com/Mikebjayb/twitchbot

That looks perfectly normal to me, except that Twitch didn’t respond to your CAP REQ command because your bot already joined a chatroom. You should send any CAP REQ commands right after connecting and before joining any channel, otherwise it won’t work.

And is the chatroom you’re trying to join a very active one? If not, then try sending a message in that same channel, preferably with a different username. If you can see them in your bot’s console window, then you’re good to go.

Thanks for the response!

I actually forgot to clarify this; the chat room I “joined” was extremely active. I tried to pick a channel that wasn’t so active it might have been off on some other high stress server, but one that was active enough for testing. I was viewing it in the browser (I wasn’t logged in). I’ll try the cap req right after connecting and see if I get a response. I’ll also edit the question.

Interesting, and you’re right, there’s something wrong with your output, although your connection is fine. Normally when you join a channel, regardless if you use CAP REQ or not, you should receive something like this. I would like to see what you did with your code, especially on the join part, if you wouldn’t mind.

Ok, I threw it on github. It’s only 3 files so it shouldn’t be much of an issue. I put the link in the question. Also here -> https://github.com/Mikebjayb/twitchbot

OK, I found your problem: your joins, CAP REQ and PRIVMSG didn’t end with \r\n (“carriage return-line feed”) like you did with PONGs and sending your username and password when you start up the bot. This is a requirement for every data you send to an IRC server, as stated in the RFC 1459 standard, otherwise the server will reject any data that doesn’t end with \r\n.

I would suggest getting rid of all the added line endings in all of your code and change one of the lines in Sock.send_data to something like this:

self.con.sendall(bytes(self.data_send + '\r\n', self.encoding))

That way, once you get to making your commands, you don’t have to add \r\n to the end of every message you create. And that makes coding easier too. Hope that helps.

1 Like

Ah awesome! Yeah I had a suspicion it would be something stupid like that. Now it works as expected. Thanks so much for your help!

1 Like

You’re welcome, man! :slight_smile:

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