# Python, custom twitch chat bot with commands

**URL:** <https://staging-discuss.dev.twitch.com/t/python-custom-twitch-chat-bot-with-commands/11611>\
**Category:** Chat and IRC\
**Created:** [August 30, 2017, 2:48pm UTC](https://staging-discuss.dev.twitch.com/t/python-custom-twitch-chat-bot-with-commands/11611 "2017-08-30T14:48:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Mojzis](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/tomas_mojzis/32/3582_2.png) [@Tomas\_Mojzis](https://staging-discuss.dev.twitch.com/u/Tomas_Mojzis)\
**Post date:** [August 30, 2017, 2:48pm UTC](https://staging-discuss.dev.twitch.com/t/python-custom-twitch-chat-bot-with-commands/11611/1 "2017-08-30T14:48:30Z")

</div>

Hello guys. I want add custom command into my python file which maked to twitch custom chat bot. I didn’t want how I can add new command. Can you help me? I attach my python file.  
From 🇨🇿

import socket, string

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

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

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

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

```
for line in temp:
    if (line[0] == "PING"):
        s.send("PONG %s\r\n" % line[1])
    else:
        parts = string.split(line, ":")

        if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
            try:
                message = parts[2][:len(parts[2]) - 1]
            except:
                message = ""
            usernamesplit = string.split(parts[1], "!")
            username = usernamesplit[0]

            if MODT:
                print username + ": " + message
               
                if message == "cau":
					Send_message (username + " Vitej na streamu ")

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

---

<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:** [September 29, 2017, 2:48pm UTC](https://staging-discuss.dev.twitch.com/t/python-custom-twitch-chat-bot-with-commands/11611/2 "2017-09-29T14:48:34Z")

</div>

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