1

So I have this code:

  from random import choice
import schedule
import telebot
token = 'token'
bot = telebot.TeleBot(token)

@bot.message_handler(commands=['start'])
def start(message):
    bot.send_message(message.chat.id, "Каждый час будет отправляться.")

@bot.message_handler(commands=['s'])
def time(message):
    def time1(message):
        a = [1,2,3,4,56,7,8,9,0,5,6,7,8,90]
        q=[]
        for i in range(10):
            q1 = choice(a)
            if q1 in q:
                q.append("")
            q.append(q1)
        bot.send_message(message.chat.id, text=f"{q}")
        print(len(q))
    schedule.every(2).seconds.do(time1(message))
    while True:
            schedule.run_pending()

@bot.message_handler()
def any_message(message):
    text = message.text
    if text == '.':
        time(message)
        return
print('WE WORK')
bot.polling()

But when it has to go again I get this error. I tried many ways to solve it but nothing works. It starts from "schedule.every(2).seconds.do(time1(message))"

TypeError: the first argument must be callable
  • 1
    My guess is that `do` requires a function which can be called, but you're sending it the *value* of `time1(message)`. If you want to call `time1(message)` inside the `do`, you probably have to wrap it in a lambda. A cursory search suggests the syntax would be `do(lambda : time1(message))` – RShields Mar 06 '22 at 21:27
  • As @RShields said, and another possible solution could be just pass `time1`, and the `do` function will call it with the message. – Ofer Arial Mar 06 '22 at 21:28
  • @RShields thanks it really works with it – Jésus Christophe Mar 07 '22 at 20:32

0 Answers0