`I'm a begginer in python, so I'm learning how to send whispers using a bot, to help my friend. I've do a research and and I arrived at the following code.
`HOST = 'irc.twitch.tv'
PORT = 6667
USER = 'bot name'
PASS = 'oauth:xxxxxxxxxx'
CHAN = 'channel here'
def abrirSocket():
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 fecharSocket(s):
s.close()
def entrar(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 = terminou(line)
def terminou(line):
if("End of /NAMES list" in line):
return False
else: return True
def enviar_key(s, usuario, mensagem):
entrar(s)
montarMSG = f'PRIVMSG jtv :/w {usuario} {mensagem}'
s.send(montarMSG.encode('utf-8'))
fecharSocket(s)
sys.exit()
enviar_key(abrirSocket(), "margoni_", "aaaaa")`
But when execute this, this appear on terminal
:tmi.twitch.tv 001 previabot :Welcome, GLHF!
:tmi.twitch.tv 002 previabot :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 previabot :This server is rather new
:tmi.twitch.tv 004 previabot :-
:tmi.twitch.tv 375 previabot :-
:tmi.twitch.tv 372 previabot :You are in a maze of twisty passages, all alike.
:tmi.twitch.tv 376 previabot :>
And don't receive any DM... Can anyone help me?
Note: I've tried to remove the buffer, to change the nick and the account, change the host and the channel, but nothing worked`
CodePudding user response:
As announced in the Deprecation of chat commands through IRC thread, sending whispers through IRC is deprecated and will be disabled entirely on Februrary 18th, 2023.
To send whispers you should use the Send Whisper API endpoint, as documented here: https://dev.twitch.tv/docs/api/reference/#send-whisper, and ensure you use a token with the user:manage:whispers
scope.
Please also keep in mind that Twitch has many anti-spam measures that are not disclosed to prevent malicious whispers, which also means that in many cases whispers will fail, either with an error or silently. While the exact nature of these anti-spam measures are not known, having 2fa and a mobile number attached to the account attempting to send whispers appears to increase the rate of success but even still it is not a method of sending messages that should be relied on with any sort of reliability.