From d34abec68c51f2be63cb85466dc399f5801d0f0c Mon Sep 17 00:00:00 2001 From: Fedor Borshev Date: Thu, 20 Jun 2024 22:20:21 +0300 Subject: [PATCH] Not throwing deletion error exception --- bot.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index c382dfb..bdd8fc0 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,6 @@ import os from telegram import Message, Update +from telegram.error import TelegramError from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler from telegram.ext.filters import TEXT, BaseFilter @@ -33,8 +34,12 @@ async def delete(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: message = update.message or update.edited_message if message is not None: - await log_message(message, action='delete') - await message.delete() + try: + await message.delete() + except TelegramError: + await log_message(message, action='deletion_error') + else: + await log_message(message, action='delete') async def introduce_myself(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: