In the python aiogram library, you can try to use the telegram.Bot.get_chat_member
method to check if a message with a given message ID exists in a chat. This method returns a telegram.ChatMember
object, which contains information about the user who sent the message.
I tried to write something that could check if a message with a given message ID exists in a chat, let me know if I understood your question correctly:
from aiogram import Bot
def check_message_exists(message_id, chat_id):
bot = Bot.get_current()
try:
message = bot.get_chat_member(chat_id, message_id)
except Exception as e:
if str(e) == "Message to delete not found":
return False
else:
raise e
return True
If the message does not exist, it will raise an exception with the message "Message to delete not found". In this case, the function returns False. If the message does exist, the function returns True.
Note that this method requires the bot to be a member of the chat in which the message was sent. If the bot is not a member of the chat, it will not be able to access the message and will raise an exception.
Let me know if it helps!