我根据视频教程编写了一个简单的Python twitch bot,但该教程没有包含耳语功能。它当前可以连接到我指定的频道的聊天,但是当我尝试让它发送耳语时没有任何反应。这是相关的代码位:
import socket
def openSocket():
s = socket.socket()
s.connect((HOST, PORT))
message = "PASS " + PASS + "\r\n"
s.send(message.encode('utf-8'))
message = "NICK " + USER + "\r\n"
s.send(message.encode('utf-8'))
message = "JOIN #" + CHAN + "\r\n"
s.send(message.encode('utf-8'))
return s
def sendMessage(s, message):
messageTemp = "PRIVMSG #" + CHAN + " :" + message + "\r\n"
s.send(messageTemp.encode('utf-8'))
print("Sent:" + messageTemp)
def sendWhisper(s, user, message):
messageTemp = "PRIVMSG #jtv :/w " + user + " " + message
s.send(messageTemp.encode('utf-8'))
import string
from Socket import sendMessage
def joinRoom(s):
readbuffer = ""
Loading = True
while Loading:
readbuffer = readbuffer + s.recv(1024).decode()
temp = readbuffer.split('\n')
readbuffer = temp.pop()
for line in temp:
print(line)
Loading = loadingComplete(line)
def loadingComplete(line):
if("End of /NAMES list" in line):
return False;
else: return True
我一直在阅读有关连接到某种群聊的内容,以便完成这项工作,但我很困惑,并没有找到我正在寻找的东西。看起来它应该是一个简单的解决方案。任何帮助表示赞赏。
答案 0 :(得分:0)
您非常亲密。在您搞砸的地方,#
前面不应有jtv
:
def sendWhisper(s, user, message):
messageTemp = "PRIVMSG jtv :/w " + user + " " + message
s.send(messageTemp.encode('utf-8'))
答案 1 :(得分:-1)
要发送IRC私信,请将PRIVMSG
发送给用户的昵称,而不是发送给某个频道,例如
PRIVMSG username :here is a message