Answer the question
In order to leave comments, you need to log in
Python Telegram Bot why doesn't scheduled messages work in a separate thread?
import telebot
import time
import schedule
import threading
def thread(my_func):
def wrapper(*args, **kwargs):
my_thread = threading.Thread(target=my_func, args=args, kwargs=kwargs)
my_thread.start()
return wrapper
@thread
def job_utro():
bot.send_message(6341*1231,"Доброе утро!")
def job_vecher():
bot.send_message(6341*1231,"Спокойной ночи!")
def job_usluga():
bot.send_message(6341*1231,"У меня для тебя кое-что есть...")
schedule.every().day.at("8:00").do(job_utro)
schedule.every().day.at("22:00").do(job_vecher)
schedule.every().sunday.at("18:39").do(job_usluga)
while True:
schedule.run_pending()
time.sleep(1)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question