You can add a connection to the API to a telegram to a function, if an error in connection, you again call this function
def API (): try : m = experept : API () api () pre> if you do not want to do it, you will have to use the database - store variables. This will help or Import Json or Import SQLite3 . If you do not want to store variables in the database, then keep them in Python using the python dictionary (dict). P.S in any case, you need Import Time . When processing a user message, you first check if there is it in the sheet, if you have, then write pass . mut = {"" id_user_1 "": {"" msg ":" 0, "min" ": 0}," Id_user_2 "" "" "" "" "" "" msg "": "min" ": 0} since the ID is a special key of the user, he will not be repeated, to tu to the user, do it mut [f "{id}" "] he will try to find it in the list.
try : mut [ f" {id} "" ] #is performed without error if the user is in the dictionary experept : mut [ f "" {id} "" ] = { "" msg "" : 0 , "" min ": Time.time ()} #when an error will register the user msg = the number of messages processed from the user mines =