diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 30b40b63..db13ccd6 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -571,3 +571,39 @@ class Message(Object): raise ValueError("This button is not supported yet") else: raise ValueError("The message doesn't contain any keyboard") + + def download(self, file_name: str = "", block: bool = True): + """Use this method as a shortcut for: + + .. code-block:: python + + client.download_media(message) + + Example: + .. code-block:: python + + message.download() + + Args: + file_name (``str``, *optional*): + A custom *file_name* to be used instead of the one provided by Telegram. + By default, all files are downloaded in the *downloads* folder in your working directory. + You can also specify a path for downloading files in a custom location: paths that end with "/" + are considered directories. All non-existent folders will be created automatically. + + block (``bool``, *optional*): + Blocks the code execution until the file has been downloaded. + Defaults to True. + + Returns: + On success, the absolute path of the downloaded file as string is returned, None otherwise. + + Raises: + :class:`Error ` + ``ValueError``: If the message doesn't contain any downloadable media + """ + return self._client.download_media( + message=self, + file_name=file_name, + block=block + )