Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
I'm not familiar with telebot, but a quick google shows that the logic is similar to how discord works.
The method of sending a message (both send_message() and reply_to()) returns you an object of the sent message, which contains incl. his ID.
You call edit_message_text() with this message ID and new text.
The only question is delay. If I understand correctly, the telebot either works sequentially (i.e. while one handler is running, the bot cannot do anything else), or uses threads to run different handlers in parallel. So you don't have much choice - good old time.sleep().
Run edit_message_text() in a loop to update the message, limiting time.sleep().
In order not to block input during multiple launches, you can use threading. Perhaps there is a more correct way in this case than threading, I don’t really know how best for telegram.
For example, filling by 10%
from threading import Thread
@bot.message_handler(commands=['start'])
def start(message):
msg = bot.send_message(message.chat.id, f'заполнение 0%')
t = Thread(target=thread_update_text, args=[msg, 'заполнение {}%'])
t.start()
def thread_update_text(message, text):
for i in range(10,110,10):
time.sleep(1)
bot.edit_message_text(chat_id=message.chat.id, message_id=message.message_id, text=text.format(i))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question