Bot not sending data properly after a set time

Hello, i’ve trying to make the bot spam some messages each certain time but if i make this time long enough no messages are shown in the chat idk why, i’m sending pongs when i recieve the pings and even sending my own pings (and when i stop being able to talk to the chat i still get pings from server) so i’m a little lost…

I think that when i make this time a little bit longer than a minute it starts going wrong (and i dont want it spamming each minute!)

Thanks a lot

Do you have an error in your console?
Aren’t you making too many requests on the API
As a basic reminder, you’re only allowed 30 requests per minute.

If you’re making this error, you’re making too many requests.
“error”: “Too Many Requests”,
“status”: 429,
“message”: “My ultimate is charging. (You have made too many requests. Please try again later.)”

429’s occur with the Helix API

Not chat.

With the oAuth changes about to come in thats 800 not 30

Chat bot’s don’t call the API to send chat messages. If you exceed the spam limit you just get disconnected.

If your bot is not a mod in the channel you will get a NOTICE with a relevant msg-id telling you you are sending too quickly, or the message is identical to the previous one, non mods must wait 30 seconds before re-sending the same message

You need to add logging for NOTICE messages and/or other Chat messaging types

I would like to answear both in the same message, but i dont know how to citate text as Barry did so i’ll try to explain (it goes for both of you :slightly_smiling_face:):

That “spam” has a very low frequency, one message each 10 minutes or so, very far away from the limit. The thing was that if the bot didnt send any message to the chat in a certain time (two secs), it became unable to send anymore (but it was still recieving pings). I was confused so i tried to force to keep that connection that seemed lost by sending an empty message each second, which worked, but its a very very unoptimal way to fix this. (instead of 1mesagge/ten minutes i send 600!) so i looked for something else but i couldnt…

If anyone has any idea where could be the mistake i made pls tell. Thank you!

Highlight the text and hit the quote button

So it’s not spam? When you say spam, we assume you mean to hammer the chat and spam it. 10 minutes or so is not spam.

Are you reply to the pings with a pong?

Sounds like you might have network conditions messing about with the connection, or you have something else going on that is stopping your code from working.

You may want to post your code so we can help debug (with secrets removed)

I meant spam, like add’s, but not exactly that, sorry for the confusion. Thanks in advance!

I think so…ill paste the code (ill try to comment the code so it is a little less messy)

import socket 
import time
import threading
import logging

def recving(name,server):

#this function was supposed to read the chat and, in some time, make it so it could read commands and act acordingly
    readbuffer = """Thread %s: starting", name)

    while continue:
        if ("PING" in readbuffer):   # the answer to the ping if recieved

            pass  # this used to write comments the chat sent into the pythons command line, but 
                     # was buggy and i just commented it
            if readbuffer[0].find("!")!=-1:
                print(name+" dijo '"+msg[:-5]+"'") """            

        #print(readbuffer[0]+readbuffer[1])"Thread %s: finishing", name)

def spam_each_certaintime(name,server):  # this is the thing
     times=900*3     # to set the freq, (in this case, whenever cont is a multiple of 300 a 
                             # message is sent)
     mensaje="Another something"
     mensaje2="The last something "
     while continuar:
        if cont%times==0:
            server.send(bytes("PRIVMSG #"+ channel +" :" +mensaje2+ "\r\n",'utf-8'))
        if (cont-(900))%times==0:

            server.send(bytes("PRIVMSG #"+ channel +" :" +mensaje+ "\r\n",'utf-8'))
        if (cont-(1800))%veces==0:

            server.send(bytes("PRIVMSG #"+ channel +" :" +mensaje3+ "\r\n",'utf-8'))

        if cont%60==0:  # ping sent each 60 seconds
            print("Send PING")
            if cont%2==0: # empty message sent to the chat to keep conn alive
                server.send(bytes("PRIVMSG #"+ channel +" :" + "\r\n",'utf-8'))

    # this down here arent suppose to mather in the error but anyway


    if __name__ == "__main__":
    # create connection
    server.send(bytes('PASS '+token+' \r\n','utf-8'))
    server.send(bytes('NICK '+user+' \r\n','utf-8'))
    server.send(bytes('JOIN #'+channel+' \r\n','utf-8'))
    format = "%(asctime)s: %(message)s"
    logging.basicConfig(format=format, level=logging.INFO,datefmt="%H:%M:%S")
    # start threads"Main    : before creating thread")
    x = threading.Thread(target=recving, args=(1,server,))
    y = threading.Thread(target=spam_each_certaintime, args=(2,server))"Main    : before running thread")
    y.start()"Main    : wait for the thread to finish")
    # x.join()
    while 1:

Ah I think the issue here is you are not terminating your lines with a CR + LF (\r\n) per the IRC spec.

So you are not ping/ponging or sending messages right.

You terminated the PASS/NICK/JOIN but not your PONG’s

1 Like

Sorry for my wrong answers.
Thanks for correcting me @BarryCarlyon I’ll know more now.

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