I am writing a bot tc on the telebot library, I am trying to send a newsletter to the user, if he chooses "yes", then a message is sent to him every day, if he chooses "no", then the newsletter is either turned off or simply not turned on
import telebot
import schedule
import time
from telebot import types
if message.text == "Подборка книг":
podborka = types.InlineKeyboardMarkup()
yes = types.InlineKeyboardButton("Да", callback_data="да")
no = types.InlineKeyboardButton("Нет", callback_data="нет")
podborka.add(yes,no)
bot.send_message(message.chat.id, "Получать рассылку?", reply_markup=podborka)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
def good_luck():
bot.send_message(call.message.chat.id, "Круто!")
job = schedule.every(1).seconds.do(good_luck)
while True:
schedule.run_pending()
time.sleep(1)
if call.message:
if call.data == "да":
godo()
else:
schedule.cancel_job(job)
In your example above you could tag the job you create like so:
Then later on when you need to clear it out do this: