title: Trying to send Message TO Twitch Chat
body: <p>I have the bot already set up to where it reacts to certain commands like using text-to-speak and playing mp3 clips when chat uses the commands, however, I can not figure out how to get to get it to respond by SENDING BACK a message INTO chat when, say, someone says "Hello Fuzzy".  I get the <strong>TypeError: a bytes-like object is required, not 'str'</strong>.  I am obviously doing something wrong but other bots that I have checked out are all coded in a different way and trying not to have to re-do the whole thing. Thanks for any help offered!!!</p>
  
  <pre><code># Config portion
  import socket
  import time
  import re
  import pyttsx3
  import soundfx
  
  
  HOST = "irc.chat.twitch.tv"  # the twitch irc server
  PORT = 6667  # always use port 6667
  NICK = "fuzzybottgaming"  # twitch username, lowercase
  PASS = "oauth:[]"  # your twitch OAuth token
  CHAN = "#[my channel]"  # the channel you want to join
  
  # Message Rate
  RATE = (20 / 30)  # messages per second
  
  #BANN HAMMER
  PATT = [
      r"swear",
      # ...
      r"some_pattern"
      ]
  
  # bot.py portion
  # Network functions go here
  
  s = socket.socket()
  s.connect((HOST, PORT))
  s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
  s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
  s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
  
  
  
  
  
  def chat(sock, msg):
      '''
      Send a chat message to the server.
      sock -- the socket over which to send the message
      msg -- the message to be sent
      '''
      sock.send("PRIVMSG #{} :{}".format(CHAN, msg))
  
  
  def ban(sock, user):
      '''
      Ban a user from the current channel.
      sock -- the socket over which to send the ban command
      user -- the user to be banned
      '''
      chat(sock, ".ban {}".format(user))
  
  
  def timeout(sock, user, secs=10):
      '''
      Time out a user for a set period of time
      sock -- the socket over which to send the timeout command
      user -- the user to be timed out
      secs -- the length of the timeout in seconds (default 600)
      '''
      chat(sock, ".timeout {}".format(user, secs))
  
  
  
  
  
  # Make sure you prefix the quotes with an 'r'
  CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
  
  
  while True:
      response = s.recv(1024).decode("utf-8")
      print(response)
      if response == "PING :tmi.twitch.tv\r\n":
         s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
         print("Pong")
      else:
          username = re.search(r"\w+", response).group(0)  # return the entire 
          match
          message = CHAT_MSG.sub("", response)
          print(username + ": " + message)
  
      if 'hello fuzzy' in message:
          s.send("Hello to you too " + username).encode("utf-8")
  
      #TTS and MP3 sound effects section taken out#
          for pattern in PATT:
              if re.match(pattern,message):
                  ban(s, username)
                  break
      time.sleep(1 / RATE)
  </code></pre>