I want to create a variable that is basically a boolean if the bot is working or not.
However, The script start to loop forever when using TeleBot.polling(), so if I set a variable in the beginning of the code like: is_bot_working = True
, the variable will always be true and vice versa.
So, how do I do to set a variable that is not affected by the loops?
That’s the code:
import telebot
bot = telebot.TeleBot(TOKEN)
is_bot_working: bool = True
@bot.message_handler(commands=['start'])
def start(message) -> None:
is_bot_working = True
@bot.message_handler(commands=['stop'])
def stop(message) -> None:
is_bot_working = False
bot.polling(non_stop=True)