Answer the question
In order to leave comments, you need to log in
How to make a reverse timer in telegram?
Hello. There are 2 methods to update received message and countdown:
def update_message(self, chat_id, message_id, new_message):
self.logger.debug(f'Update message {message_id}: {new_message}')
self.bot.edit_message_text(chat_id=chat_id, message_id=message_id, text=new_message)
def create_timer(self, timeout_secs, callback, *args, **kwargs):
if not callable(callback):
raise TypeError('Ожидаем функцию на вход')
if not timeout_secs:
raise TypeError("Не могу запустить таймер на None секунд")
if args:
raise TypeError(f"create_timer() takes 2 positional arguments but {len(args) + 2} were given")
def wrapper(context):
callback(**kwargs)
self.job_queue.run_once(wrapper, timeout_secs)
def create_countdown(self, timeout_secs, callback, *args, **kwargs):
if not callable(callback):
raise TypeError('Ожидаем функцию на вход')
if not timeout_secs:
raise TypeError("Не могу запустить таймер на None секунд")
if args:
raise TypeError(f"create_countdown() takes 2 positional arguments but {len(args) + 2} were given")
def wrapper(context):
job = context.job
job.context -= 1
try:
callback(job.context, **kwargs)
except Exception as error:
traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr, limit=-3)
job.schedule_removal()
if job.context <= 0:
job.schedule_removal()
first_callback = lambda context: callback(timeout_secs, **kwargs)
self.job_queue.run_once(first_callback, 0)
self.job_queue.run_repeating(wrapper, 1, context=timeout_secs)
Answer the question
In order to leave comments, you need to log in
Wrap your code in a code tag.
I can't figure out how to change the message in the countdown
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question