I'm coding a pretty simple Twitch Chatbot in Python and I have all my "commands" running in if statements (basically if the chatbot sees something in chat it activates).
However, I want to add a cooldown of about 3 seconds or really an amount of time per command (or if statement), so that I can customize it depending. To do that I tried this (pseudo code)
if command is seen in chat
newtimestamp = create timestamp at now
if (newtimestamp - previoustimestamp) > 30
execute the command
make (previoustimestamp)
else
return
but that didn't work because obviously it does not detect the (previoustimestamp) on the first run since it's not declared yet, but when you declare it, it declares it every time the command is run.
So is there a way to make a declaration only once at the beginning of an if statement and then ignore it subsequently every other time? Or any other ideas? I'm still a pretty novice programmer so I apologize.
Here's an example code that I would want the cooldown for, something quite simple
if "!redb match" in message:
x = str(randint(1, 100))
realmessage = message.replace('!redb ship ', '')
array = realmessage.split(' ')
person1 = array[0]
person2 = array[1]
if ((9 - 2) > 5):
sendMessage(s, person1 + " and " + person2 + "have a " + x + "% love compatibility <3")
else:
break
Aucun commentaire:
Enregistrer un commentaire