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()
joinRoom(s)
readbuffer = “”

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

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

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.

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

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

Edited:
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.