使用python在IRC中发送消息时遇到问题

使用python在IRC中发送消息时遇到问题,python,python-3.x,irc,twitch,twitch-api,Python,Python 3.x,Irc,Twitch,Twitch Api,我试图使用python创建一个irc bot,但我遇到了一个错误。当我尝试检查发送的消息时,PRIVMSG不会向聊天室发送消息,而是输出testprint语句。如果我只是尝试在收到任何东西时发送消息,它就会发送消息。我在代码中对此进行了注释。这是我第一次尝试这样做,如果我对使用python套接字有点缺乏经验,那么很抱歉 #connect.py #connects to twitch irc and presents a class to b import cfg import socket i

我试图使用python创建一个irc bot,但我遇到了一个错误。当我尝试检查发送的消息时,PRIVMSG不会向聊天室发送消息,而是输出testprint语句。如果我只是尝试在收到任何东西时发送消息,它就会发送消息。我在代码中对此进行了注释。这是我第一次尝试这样做,如果我对使用python套接字有点缺乏经验,那么很抱歉

#connect.py
#connects to twitch irc and presents a class to b

import cfg
import socket
import time

def ban(sock, user):
    chat(sock, ".ban {}".format(user))

def timeout(sock, user, secs=600):
    chat(sock, ".timeout {}".format(user, secs))

# network functions go here

s = socket.socket()
s.connect((cfg.HOST, cfg.PORT))
s.send("PASS {}\r\n".format(cfg.PASS).encode("utf-8"))
s.send("NICK {}\r\n".format(cfg.NICK).encode("utf-8"))
s.send("JOIN {}\r\n".format(cfg.CHAN).encode("utf-8"))

while True:
    time.sleep(0.1)
    response = s.recv(1024).decode("utf-8")
    print(response)
    if response == "PING :tmi.twitch.tv\r\n":
        s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
    elif "hi" in response:
        #prints Condition Worked but doesn't send message
        print("Condition Worked")
        s.send(("PRIVMSG #garrett_the_savage :hello"+"\r\n").encode('utf-8'))
    else
        #sends a message when anything is received from the socket
        s.send(("PRIVMSG #garrett_the_savage :hello"+"\r\n").encode('utf-8'))

编辑:我有一个名为cfg.py的单独文件,其中包含一些用于连接的变量。

Twitch中的任何消息都不适用于您,因为它们使用的是
CAP
IRC v3协议。阅读此答案以了解更多信息,并在代码中添加
CAP
消息我理解您试图提供帮助,但我认为发送python中的内容比发送java中的内容更有帮助。。。