J
J
James_Obry2021-12-28 22:54:19
Bots
James_Obry, 2021-12-28 22:54:19

How to make a telebot error handler?

I am writing a bot in telegram, and imagined the situation while the bot is parsing a huge database (seconds 2), the user can stop the bot, and an error pops up that the chat where the bot tried to send a message was not found
. In the aiogram library, all this can be prevented by the following code:

@dispatcher.errors_handler(exception=BotBlocked)
async def error_bot_blocked(update: types.Update, exception: BotBlocked):
    print(f"Меня заблокировал пользователь!\nСообщение: {update.message.chat.id}\nОшибка: {exception}")
    return True


Please tell me how this can be implemented on the telebot library ??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
InternetMaster, 2021-12-29
@InternetMaster

Well, it's try-except straight out of the Python box.

try:
    bot.send_message(message.chat.id, 'Поиск выполнен успешно')
except Exception:
    print('пользователь заблокировал бота')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question