Working with scedule and telebot at the same time

Viewed 202

I'm working with a program that uses those libraries :

  • telebot
  • schedule

And I want to schedule the program to execute the functions every certain time like this:

from time import sleep
import schedule,telebot

token = 'MY TOKEN'
bot = telebot.TeleBot(token)

def check():
    @bot.message_handler(commands=['start'])
    def send_ms(message):
        bot.send_message(message.chat.id,'Welcome '+str(message.from_user.first_name)+'!!')
        mss = 'Welcome to my bot!'
        bot.send_message(message.chat.id,mss)

def pr():
    print('Hello World')


schedule.every().second.do(pr)
schedule.every().second.do(check)

Below this code if I put bot.polling() instead of this line here it's gonna be stuck in an infinite loop.

I can either do this

while True:
    schedule.run_pending()
    sleep(1)

or this

bot.polling()

in either way it's gonna be stuck in an infinite loop and gonna ignore all the code below it! How Can I Solve This Problem!

0 Answers
Related