Answer the question
In order to leave comments, you need to log in
How to make a message listener and perform something in a loop for a tg bot at the same time?
I started learning Python, I want to make a simple bot that checks the rss feed and sends a link to the channel if there is a new post. But at the same time I want to make it possible to turn off news and add feeds. This requires the bot to listen to messages. Below is the code I have tried. Swapped the bot poll and the cycle, but one thing works. Tell me what to read, where to see. Bots with similar functions looked in the github, but there is something very complicated
import telebot, time
from config.config import BOT_TOKEN
bot = telebot.TeleBot(BOT_TOKEN)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
@bot.message_handler(func=lambda message: True)
def echo_all(message):
bot.reply_to(message, message.text)
bot.polling()
while True:
print('Hello')
time.sleep(1)
Answer the question
In order to leave comments, you need to log in
I advise you to read about the basics of asynchronous programs.
But if on your fingers, consider that the program will not exit from bot.polling() until it completes. She will spin there, wait for the event, and pull the handlers.
Therefore, everything that you want to teach a bot to do, you need to do
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question