79161596

Date: 2024-11-06 07:01:38
Score: 2
Natty:
Report link

I faced the same problem, but I wanted to do without terrible crutches in the spirit of sending messages and it was required that users could not notice this check. I suggest such a solution - try to set an empty (None) reaction. If there is no message, there will be one of two errors, if there is a message, then the try block will either be processed successfully (it is unknown why, because I never set a reaction) or there will be a REACTION_EMPTY error.

Code:

async def check_message_exists(self, message_id, chat_id):
    try:
        await self.bot.set_message_reaction(chat_id, message_id, None)

        return True

    except Exception as e:
        match str(e):
            case "Telegram server says - Bad Request: REACTION_EMPTY":
                return True

            case "Telegram server says - Bad Request: MESSAGE_ID_INVALID":
                return False

            case "Telegram server says - Bad Request: message to react not found":
                return False

        raise e

Note: under different circumstances, I receive either MESSAGE_ID_INVALID or "message to react not found", I would be very grateful if aiogram experts would explain why there are as many as 2 errors, when I checked deleted by admin or base group member message...

Reasons:
  • RegEx Blacklisted phrase (2): I would be very grateful
  • Long answer (-1):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Alexey Zaliznuak