Bot doesn't receive whispers from user (Python)

I’m writing a bot that needs to read and post whispers.

Almost everything works as expected except bot doesn’t receive whispers.

At the moment the bot can read from and send messages to public channel. It also can send whispers to (at least) me, and I can confirm it by reading them in the browser. With the code below I can see messages from users in public channel in terminal but I don’t see whispers sent from user to bot there. I am not very familiar with IRC protocol, but I believe with the code below I am outputting everything that is sent to me. Unrelated code is removed from snippet.

s = socket.socket()
s.connect(('irc.chat.twitch.tv', 6667))
s.send(f'PASS {config.PASS}\r\n'.encode('utf-8'))
s.send(f'NICK {config.NICK}\r\n'.encode('utf-8'))
s.send(f'JOIN #{config.CHANNEL}\r\n'.encode('utf-8'))

# I can see both in the browser 
utils.sendMessage(s, 'Public test')                           # in public chat
utils.sendPrivateMessage(s, config.CHANNEL, 'Private test')   # in PM

while True:
    response = s.recv(1024).decode('utf-8')
    print(response)    # prints public messages, but not whispers sent to bot
    time.sleep(1)

Where should I look to fix this?
I’ve read all related threads here that I was able to find but it didn’t help.

Your problem is you are not requesting that capability from twitch. the line after s.connect put

s.send(f'CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands\r\n'.encode('utf-8'))

That should then request everything twitch has to offer and send it your way.

1 Like

Thank you, it works now!
In fact I’ve tried to send something similar to your solution, but it didn’t work:

s.send('CAP REQ :twitch.tv/tags twitch.tv/commands'.encode('utf-8'))

Also, after some research, I’ve discovered two things:

  1. Only twitch.tv/commands is required of those 3 things for receiving whispers.
  2. Don’t forget ‘\r\n’ at the end!

Although my problem turned out to be #2, without your solution I wasn’t sure that the problem was related to that command.

Oh lol

But yeah, i’d recommend making a function to append \r\n to everything as well as encoding it to utf-8 to make things easier on yourself and be less confusing.

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