# Twitchbot doesn't connect to the server

**URL:** <https://discuss.dev.twitch.com/t/twitchbot-doesnt-connect-to-the-server/9258>\
**Category:** Chat and IRC\
**Created:** [February 14, 2017, 7:33pm UTC](https://discuss.dev.twitch.com/t/twitchbot-doesnt-connect-to-the-server/9258 "2017-02-14T19:33:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![heardbag](https://avatars.discourse-cdn.com/v4/letter/h/3d9bf3/32.png) [@heardbag](https://discuss.dev.twitch.com/u/heardbag)\
**Post date:** [February 14, 2017, 7:33pm UTC](https://discuss.dev.twitch.com/t/twitchbot-doesnt-connect-to-the-server/9258/1 "2017-02-14T19:33:53Z")

</div>

I have made a twitchbot, in the console it gives me the “your are in a maze” thing and successfully reads messages from the chat and even pings and pongs but, doesn’t send the messages i tell it to write in chat. here is my bot code

import cfg  
import BotFunc  
import socket  
import re  
import time,thread  
from time import sleep

def main():  
s = socket.socket()  
s.connect((cfg.HOST, cfg.PORT))  
s.send(“PASS {}\r\n”.format(cfg.PASS).encode(“utf-8”))  
s.send(“NICK {}\r\n”.format(cfg.NICK).encode(“utf-8”))  
s.send(“JOIN {}\r\n”.format(cfg.CHAN).encode(“utf-8”))

```
CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
BotFunc.chat(s, "I LIVE!!!")

thread.start_new_thread(BotFunc.threadFillOPList, ())

while True:
    response = s.recv(1024).decode("utf-8")
    if response == "PING :tmi.twitch.tv\r\n":
        print("Ping")
        s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
        print("Pong")
    else:
        username = re.search(r"\w+", response).group(0)
        message = CHAT_MSG.sub("", response)
        print(response)

    if message.strip == "!info": #and BotFunc,isOp(username)
        BotFunc.chat(s, "test 1")
        BotFunc.chat(s, "test 2")
        BotFunc.chat(s, "test 3")
sleep(1)

```

if **name** == “ **main** ”:  
main()

and here is my message sending function

def chat(sock, msg):  
sock.send(“PRIVMSG #{} :{}\r\n”.format(cfg.CHAN, msg))

i would greatly appreciate your input and suggestions as to how to fix this, it is important.

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [February 14, 2017, 7:41pm UTC](https://discuss.dev.twitch.com/t/twitchbot-doesnt-connect-to-the-server/9258/2 "2017-02-14T19:41:18Z")

</div>

Based on you successfully receiving messages, your cfg.CHAN has # in it, so you’re sending 2.

---

<div class="post-metadata">

**Author:** ![heardbag](https://avatars.discourse-cdn.com/v4/letter/h/3d9bf3/32.png) [@heardbag](https://discuss.dev.twitch.com/u/heardbag)\
**Post date:** [February 14, 2017, 7:44pm UTC](https://discuss.dev.twitch.com/t/twitchbot-doesnt-connect-to-the-server/9258/3 "2017-02-14T19:44:31Z")

</div>

so do i remove a #?

---

<div class="post-metadata">

**Author:** ![heardbag](https://avatars.discourse-cdn.com/v4/letter/h/3d9bf3/32.png) [@heardbag](https://discuss.dev.twitch.com/u/heardbag)\
**Post date:** [February 14, 2017, 7:49pm UTC](https://discuss.dev.twitch.com/t/twitchbot-doesnt-connect-to-the-server/9258/4 "2017-02-14T19:49:56Z")

</div>

so i added a # in

s.send(“JOIN #{}\r\n”.format(cfg.CHAN).encode(“utf-8”))

and removed a # in

sock.send(“PRIVMSG {} :{}\r\n”.format(cfg.CHAN, msg))

and now it can send but not recieve

---

<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 16, 2017, 7:49pm UTC](https://discuss.dev.twitch.com/t/twitchbot-doesnt-connect-to-the-server/9258/5 "2017-03-16T19:49:56Z")

</div>

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