-1

I have these 2 functions, by the end of each bot will send random message from txt file. For example i want to schedule 1 func at 9 AM, and second at 10 PM. But module schedule doesn't work and idk why.

@bot.message_handler(commands=['start'])
def foo(message):
    keyboard = types.InlineKeyboardMarkup()
    url_button = types.InlineKeyboardButton(text="Перейти на опрос", 
    url="https://docs.google.com/forms/d/e/")
    keyboard.add(url_button)
    bot.send_message(message.chat.id, "Привет! Нажми на кнопку и перейди в опрос.", 
    reply_markup=keyboard)
    lines = open("test.txt", encoding="utf8").read().splitlines()
    randomLine1 = random.choice(lines)
    bot.send_message(message.chat.id, text=randomLine1)
    print(randomLine1)


def doo(message):
    keyboard = types.InlineKeyboardMarkup()
    url_button = types.InlineKeyboardButton(text="Перейти на опрос2", 
    url="https://docs.google.com/forms/d/e/")
    keyboard.add(url_button)
    bot.send_message(message.chat.id, "Привет! Нажми на кнопку и перейди в опрос.2", 
    reply_markup=keyboard)
    lines = open("test.txt", encoding="utf8").read().splitlines()
    randomLine2 = random.choice(lines)
    bot.send_message(message.chat.id, text=randomLine2)

So i've gone through all the docs but coldn't find the answer to my question

CallMeStag
  • 5,467
  • 1
  • 7
  • 22
Max
  • 1
  • 2

1 Answers1

0

I can't say what went wrong since you didn't show what you tried, but this worked for me

import schedule
import time

def foo():
    print("foo")

def doo():
    print("doo")

schedule.every().day.at("9:00").do(foo)
schedule.every().day.at("22:00").do(dob)

while True:
    schedule.run_pending()
    time.sleep(1)
valtteri k
  • 46
  • 3