# How to announce subs/gifted subs from twitch chat

**URL:** <https://discuss.dev.twitch.com/t/how-to-announce-subs-gifted-subs-from-twitch-chat/20065>\
**Category:** Chat and IRC\
**Created:** [February 16, 2019, 3:18pm UTC](https://discuss.dev.twitch.com/t/how-to-announce-subs-gifted-subs-from-twitch-chat/20065 "2019-02-16T15:18:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Arnum](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Frank\_Arnum](https://discuss.dev.twitch.com/u/Frank_Arnum)\
**Post date:** [February 16, 2019, 3:18pm UTC](https://discuss.dev.twitch.com/t/how-to-announce-subs-gifted-subs-from-twitch-chat/20065/1 "2019-02-16T15:18:10Z")

</div>

Hey everyone, I am wondering how I can make my twitch bot notice that there is a sub/gifted sub and send a message to the user saying “thanks for the sub username” any way I can do this is python? Please lmk asap and if you need more info to help just reply what you need thanks!

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [February 16, 2019, 3:36pm UTC](https://discuss.dev.twitch.com/t/how-to-announce-subs-gifted-subs-from-twitch-chat/20065/2 "2019-02-16T15:36:27Z")

</div>

You’ll need to enable Commands and Tags capabilities

> **[Chat & Chatbots](https://dev.twitch.tv/docs/irc/)**
>
> Twitch Chat & Chatbots

And consume the relevant USERNOTICE’s

> **[Twitch IRC Tags](https://dev.twitch.tv/docs/irc/tags/#usernotice-twitch-tags)**
>
> Twitch IRC Tags Most IRC messages provide enough information that you can figure out what happened. For example, in the following PRIVMSG message, you know that user abc posted HeyGuys in the xyz channel. :abc!abc@abc.tmi.twitch.tv PRIVMSG #xyz...

You may need to modify or obtain a IRCv3 compatible python library for IRC

---

<div class="post-metadata">

**Author:** ![Frank\_Arnum](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Frank\_Arnum](https://discuss.dev.twitch.com/u/Frank_Arnum)\
**Post date:** [February 16, 2019, 3:51pm UTC](https://discuss.dev.twitch.com/t/how-to-announce-subs-gifted-subs-from-twitch-chat/20065/5 "2019-02-16T15:51:20Z")

</div>

WOW! thanks for the fast response! How do I add these capabilities and tags into python? you also mentioned I may have to obtain a new IRCv3? What is that? How do I obtain it?

```
HERE'S MY CODE:

```

from **future** import print\_function  
import random  
import socket, string

# Set all the variables necessary to connect to Twitch IRC

HOST = “[irc.twitch.tv](http://irc.twitch.tv)”  
NICK = “your twitch id”  
PORT = 6667  
PASS = “your oauth code”  
readbuffer = “”  
MODT = False

# Connecting to Twitch IRC by passing credentials and joining a certain channel

s = socket.socket()  
s.connect((HOST, PORT))  
s.send("PASS " + PASS + “\r\n”)  
s.send("NICK " + NICK + “\r\n”)  
s.send(“JOIN #channel \r\n”)

# Method for sending a message

def Send\_message(message):  
s.send(“PRIVMSG #channel :” + message + “\r\n”)

while True:  
readbuffer = readbuffer + s.recv(1024)  
temp = string.split(readbuffer, “\n”)  
readbuffer = temp.pop()

```
for line in temp:
    # Checks whether the message is PING because its a method of Twitch to check if you're afk
    if (line[0] == "PING :tmi.twitch.tv"):
        s.send(bytes("PONG :tmi.twitch.tv\r\n", "UTF-8"))
        print("PONG SENT")
    else:
        # Splits the given string so we can work with it better
        parts = string.split(line, ":")

        if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
            try:
                # Sets the message variable to the actual message sent
                message = parts[2][:len(parts[2]) - 1]
            except:
                message = ""
            # Sets the username variable to the actual username
            usernamesplit = string.split(parts[1], "!")
            username = usernamesplit[0]
           
            # Only works after twitch is done announcing stuff (MODT = Message of the day)
            if MODT:
                print (username + ": " + message)
               
                # You can add all your plain commands here
 
			
					

            for l in parts:
                if "End of /NAMES list" in l:
                    MODT = True

```

USING PYTHON: Python 2.7.13 |Enthought, Inc. (x86\_64)| (default, Mar 2 2017, 16:05:12) [MSC v.1500 64 bit (AMD64)]  
Type “copyright”, “credits” or “license” for more information.

IPython 5.3.0 – An enhanced Interactive Python.  
? -\> Introduction and overview of IPython’s features.  
%quickref -\> Quick reference.  
help -\> Python’s own help system.  
object? -\> Details about ‘object’, use ‘object??’ for extra details.

---

<div class="post-metadata">

**Author:** ![Frank\_Arnum](https://avatars.discourse-cdn.com/v4/letter/f/71e660/32.png) [@Frank\_Arnum](https://discuss.dev.twitch.com/u/Frank_Arnum)\
**Post date:** [February 16, 2019, 3:52pm UTC](https://discuss.dev.twitch.com/t/how-to-announce-subs-gifted-subs-from-twitch-chat/20065/6 "2019-02-16T15:52:21Z")

</div>

The code formatting got messed up while pasting it here dont know why but starts after “HERE’S MY CODE”

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [March 18, 2019, 3:52pm UTC](https://discuss.dev.twitch.com/t/how-to-announce-subs-gifted-subs-from-twitch-chat/20065/7 "2019-03-18T15:52:21Z")

</div>

Closed on March 18, 2019, 3:52pm UTC

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