Z
Z
Zhenia Bel2020-10-24 22:16:42
Python
Zhenia Bel, 2020-10-24 22:16:42

Schedule not working, why?

Introduced schedule so that a message is sent every 10 minutes, but for some reason it only sends once and crashes. What is the reason?
Here is the code:

import schedule
import time
import random
import telebot


bot = telebot.TeleBot('Token')
eng_word = ['weather — погода','fine — прекрасный','terrible — ужасный','cold — холодный','hot — жаркий']

@bot.message_handler(commands=['start'])
def welcome(message):
    bot.send_message(message.chat.id, "Привет, {0.first_name}!\nЯ -<b>{1.first_name}</b>, бот который поможет выучить английские слова)".format(message.from_user, bot.get_me()),
                     parse_mode='html')

@bot.message_handler(commands= ['learn'])
def learn(message):
    bot.send_message(message.chat.id, random.choice(eng_word))
    schedule.every(10).minutes.do(learn)

while True:
    schedule.run_pending()
    time.sleep(1)
    bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-10-24
@SoreMix

1. What specifically processes schedule? After all, you don’t have a single function for it
2. Crash because you are trying to launch the bot every second

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question