Making a Python Twitch Bot

Hi, i’m making a twitchbot and i encountered an issue with this code

def chat(sock, msg):

sock.send("PRIVMSG #{} :{}".format(cfg.CHAN, msg))

import cfg
import socket
import re

Network Stuff

s = socket.socket()
s.connect((cfg.TWITCH, cfg.PORT))
s.send(“PASS {}\r\n”.format(cfg.OAUTH).encode(“utf-8”))
s.send(“NICK {}\r\n”.format(cfg.BOT).encode(“utf-8”))
s.send(“JOIN {}\r\n”.format(cfg.HOST).encode(“utf-8”))

CHAT_MSG=re.compile(r"^:\w+!\w+@\ PRIVMSG #\w+ :")

while True:
response = s.recv(1024).decode(“utf-8”)
if response == “PING\r\n”:
username ="\w+", response).group(0)
message = CHAT_MSG.sub("", response)
print(username + ": " + message)
for in
if re.match(, message):
s.send(s, “,message”)#Command Function Goes Here

it says it connects to the channel but doesn’t send/recieve any information, i would really appreciate your input and help

JOIN’s cfg.HOST missing #? Is it all lowercase?

Sadly your Python code lost its formatting but I believe I found your “cannot send” issue.

Twitch IRC chat does need the “\r\n” at the end of each message string and I do not see that in your code for sending messages to the chat. You have it for the PONG reply.

As for receiving, did you check your code as 3ventic suggested?

Finally, are you using Python 2.7 or Python 3.x?

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