From 7752aef33855d1fe317d907288342493726d2c1a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 3 Jun 2018 17:50:24 +0200 Subject: [PATCH] Add delete convenience method to Message objects --- pyrogram/client/types/message.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 1ffab8ed..a2a1ceab 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -424,3 +424,39 @@ class Message(Object): message_ids=self.message_id, disable_notification=disable_notification ) + + def delete(self, revoke: bool = True): + """Use this method as a shortcut for: + + .. code-block:: python + + client.delete_messages( + chat_id=chat_id, + message_ids=message.message_id + ) + + Example: + .. code-block:: python + + message.delete() + + Args: + revoke (``bool``, *optional*): + Deletes messages on both parts. + This is only for private cloud chats and normal groups, messages on + channels and supergroups are always revoked (i.e.: deleted for everyone). + Defaults to True. + + Returns: + True on success. + + Raises: + :class:`Error ` + """ + self.client.delete_messages( + chat_id=self.chat.id, + message_ids=self.message_id, + revoke=revoke + ) + + return True