# Bot doesn't receive whispers from user (Python)

**URL:** <https://staging-discuss.dev.twitch.com/t/bot-doesnt-receive-whispers-from-user-python/15801>\
**Category:** Chat and IRC\
**Created:** [May 15, 2018, 1:41am UTC](https://staging-discuss.dev.twitch.com/t/bot-doesnt-receive-whispers-from-user-python/15801 "2018-05-15T01:41:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![denai](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@denai](https://staging-discuss.dev.twitch.com/u/denai)\
**Post date:** [May 15, 2018, 1:41am UTC](https://staging-discuss.dev.twitch.com/t/bot-doesnt-receive-whispers-from-user-python/15801/1 "2018-05-15T01:41:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xDemonsxXxSaintx](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/xdemonsxxxsaintx/32/4144_2.png) [@xDemonsxXxSaintx](https://staging-discuss.dev.twitch.com/u/xDemonsxXxSaintx)\
**Post date:** [May 15, 2018, 2:18am UTC](https://staging-discuss.dev.twitch.com/t/bot-doesnt-receive-whispers-from-user-python/15801/2 "2018-05-15T02:18:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![denai](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@denai](https://staging-discuss.dev.twitch.com/u/denai)\
**Post date:** [May 15, 2018, 2:43am UTC](https://staging-discuss.dev.twitch.com/t/bot-doesnt-receive-whispers-from-user-python/15801/3 "2018-05-15T02:43:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xDemonsxXxSaintx](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/xdemonsxxxsaintx/32/4144_2.png) [@xDemonsxXxSaintx](https://staging-discuss.dev.twitch.com/u/xDemonsxXxSaintx)\
**Post date:** [May 15, 2018, 2:47am UTC](https://staging-discuss.dev.twitch.com/t/bot-doesnt-receive-whispers-from-user-python/15801/4 "2018-05-15T02:47:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2spem0quai2ol.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://staging-discuss.dev.twitch.com/u/system)\
**Post date:** [June 14, 2018, 2:48am UTC](https://staging-discuss.dev.twitch.com/t/bot-doesnt-receive-whispers-from-user-python/15801/5 "2018-06-14T02:48:03Z")

</div>

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