Bot can receive messages, but sent messages do not show up in chat

Hi all!

I am writing (Python3.6) a bot that reads all messages sent to a channel, and then echos those messages back to the chat. I know there isn’t much use for this bot, but ideally it will serve as a skeleton for some future projects.

I currently have it connecting to a channel and reading all messages that are sent to that channel, but it’s have issues when it comes to sending messages to the channel chat (I actually had it working previously, but for some reason it is not working now). It prints what is seemingly the correctly formatted message to my command line output, but it never shows up in the channel chat. I’m thinking that I may be screwing up some formatting when I try to have it send a message.

I’ve checked the other topics here, triple checked to make sure that my channel and username are all lowercase, and that my oath key is correct. I’m hoping that someone can help point out the error that I can’t seem to find.

Sorry in advance for my formatting, this is my first post.

Behavior and output:

from Socket import openSocket, sendMessage
from Initialize import joinRoom
from Settings import RATE
import time, socket, string, re
s = openSocket()
CHAT_MESSAGE=re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
while True:
	#get all lines that come in
	print(readbuffer) #print everything that comes in
	if readbuffer == "PING\r\n":
		username ="\w+", readbuffer).group(0) #parse username and message
		message = CHAT_MESSAGE.sub("", readbuffer) 
		print(username + ": " + message)
		sendMessage(s, message) #copy what user says and send it!

import socket
from Settings import HOST, PORT, PASS, BOT, CHANNEL

#opens socket, connects BOT to twitch,
#joins channel CHANNEL and returns socket.
def openSocket():
	s.connect((HOST, PORT))

	password="PASS {}\r\n".format(PASS).encode()

	username="NICK {}\r\n".format(BOT).encode()

	joinChannel="JOIN #{}\r\n".format(CHANNEL).encode()
	return s

def sendMessage(s, message):
	messageTemp="PRIVMSG #{} :{}\r\n".format(CHANNEL, message).encode()
	print("BOT SENT MESSAGE: "+messageTemp.decode())

import string
from Socket import sendMessage

def joinRoom(s):
	Loading = True

	#TODO clean this up
	while Loading:
		newbuffer = readbuffer.join(s.recv(1024).decode())
		temp = newbuffer.split("\n")
		newbuffer = temp.pop

		for line in temp:
			Loading = loadingComplete(line)
			if (not Loading):
	sendMessage(s, "Bot's first message to chat") #send Kappa upon joining room
	print("JOINROOM END")

def loadingComplete(line):
	if ("End of /NAMES list" in line):
		return False
		return True

RATE=(20/30) #20 messages per 30 seconds

Any suggestions or help is appreciated, thanks for looking!

EDIT/UPDATE1: For some reason, the bot can send to it’s own channel, but cannot receive messages in it’s own channel. Here is the same program running but I’ve changed the channel from “loslobodev” (my main) to “pikaboyden”(my bot’s channel)

UPDATE2: It also is able to read all messages on a popular channel, but still cannot send from the bot. If I log into the account I can still manually type in chat and participate so I know the account is not banned.

Try using instead of just to see if that changes anything.

Shouldn’t make a difference; both CNAME for the same AWS domain name and raw sockets don’t care (whereas websockets do).

I tried using and it didn’t change functionality. I ended up migrating the code to Python2.7 and was able to get what I wanted for my purposes. I’ll still try to fix the 3.6 code and I’ll be back here with a solution if I find one. Thanks for your suggestions!

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