D
D
Danya  2020-08-24 20:57:50
Python
Danya  , 2020-08-24 20:57:50

TelegramBOT message with timer?

How to send a message through Telebot that says "Wait 15 seconds" after a second it changes "Wait 14 seconds". CHANGED and not deleted.
Here is the code that I wrote:

bot.send_message(message.chat.id, 'Ждите... 15')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 14')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 13')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 12')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 11')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 10')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 9')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 8')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 7')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 6')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 5')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 4')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 3')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 2')
    time.sleep(1)
    bot.edit_message_text(message.chat.id, message.message_id, 'Ждите... 1')


Here is the log from the console:
2020-08-24 20:57:15,502 (util.py:68 WorkerThread1) ERROR - TeleBot: "ApiException occurred, args=('A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:\n[b\'{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}\']',)
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\util.py", line 62, in run
    task(*args, **kwargs)
  File "C:\Users\User\Desktop\blocked.py", line 52, in dadas
    bot.edit_message_text(message.message_id, 'Ждите... 14')
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\__init__.py", line 1185, in edit_message_text
    disable_web_page_preview, reply_markup)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\apihelper.py", line 772, in edit_message_text
    return _make_request(token, method_url, params=payload, method='post')
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\apihelper.py", line 69, in _make_request
    return _check_result(method_name, result)['result']
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\telebot\apihelper.py", line 88, in _check_result
    raise ApiException(msg, method_name, result)
telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}']
"
2020-08-24 20:57:15,506 (__init__.py:455 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}']"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-08-24
@MrBrainop

Read what parameters the function takes.
See what parameters the IDE offers for the function
It accepts text, chat ID, message ID.

def edit_message_text(self, text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, disable_web_page_preview=None, reply_markup=None)

You pass the chat ID, message ID, text
https://github.com/eternnoir/pyTelegramBotAPI/blob...
Well, the implementation, of course, is also strange. Why do you not like cycles?
for x in range(1, 16):
    bot.edit_message_text('Ждите {} сек'.format(x), message.chat.id, message.message_id)
    time.sleep(1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question