S
S
Sergey Bondarenko2019-05-29 13:46:28
Python
Sergey Bondarenko, 2019-05-29 13:46:28

How, after launching the bot (telebot), immediately start executing the function without user interaction?

Hello, I created a bot, wrote sending messages after a while and I don’t understand how to make the bot run this script without user interaction?
here is the code:

import telebot, random, time


bot = telebot.TeleBot("token")


@bot.message_handler(commands = ['start'])
def events(message):
    msg = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
    while True:
        bot.send_message(message.chat.id, random.choice(msg))
        time.sleep(5.0)

bot.polling()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question