My Python Twitch bot wont PONG

my bot commands work fine but every time twitch PING me my bot will not PONG back

import string
from Read import getUser, getMessage
from Socket import openSocket, sendMessage
from Initialize import joinRoom

s = openSocket()
readbuffer = “”

while True:
readbuffer = readbuffer + s.recv(1024)
temp = string.split(readbuffer, “\n”)
readbuffer = temp.pop()

	for line in temp:
		if "PING" in line:
			s.send(line.replace("PING", "PONG"))
			print("i just sent a pong")
		user = getUser(line)
		message = getMessage(line)
		print user + " typed :" + message
		if "!build" in message:
			sendMessage(s, "")

From what i’m seeing you need to encode the data being sent.
It’s been awhile since I messed around with python but I think one of these should work.

s.send(line.replace("PING", "PONG").encode("utf-8"))

s.send(bytes(line.replace("PING", "PONG")).encode("utf-8"))

Come to think of it, you might just be able to use that sendMessage function from the socket library like such.
sendMessage(s, line.replace("PING", "PONG"))

And you need check you are sending \r\n on the end to trigger the send with the correct line ending

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