get_messages()¶
- Client.get_messages()¶
Get one or more messages from a chat by using message identifiers. You can retrieve up to 200 messages at once.
Usable by Users Bots
You must use exactly one of
message_idsOR (chat_id,message_ids) ORlink.- Parameters:¶
chat_id (``int`` | ``str``, *optional*, **kwargs) – Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use “me” or “self”. For a contact that exists in your Telegram address book you can use his phone number (str).
message_ids (``int`` | Iterable of ``int``, *optional*) – Pass a single message identifier or an iterable of message ids (as integers) to get the content of the message themselves.
replies (``int``, *optional*) – The number of subsequent replies to get for each message. Pass 0 for no reply at all or -1 for unlimited replies. Defaults to 1. Is ignored if
is_scheduledparameter is set.is_scheduled (``bool``, *optional*) – Whether to get scheduled messages. Defaults to False. Only supported if both
chat_idandmessage_idsare passed. Other parameters are ignored when this is set.link (``str``) – A link of the message, usually can be copied using
Copy Linkfunctionality OR obtained usinglinkORExportMessageLink
- Returns:¶
:obj:`~pyrogram.types.Message` | List of :obj:`~pyrogram.types.Message` | :obj:`~pyrogram.types.DraftMessage` (In case *message_ids was not*)
a list, a single message is returned, otherwise a list of messages is returned.
Example
# Get one message await app.get_messages(chat_id=chat_id, message_ids=12345) # Get more than one message (list of messages) await app.get_messages(chat_id=chat_id, message_ids=[12345, 12346]) # Get message by ignoring any replied-to message await app.get_messages(chat_id=chat_id, message_ids=message_id, replies=0) # Get message with all chained replied-to messages await app.get_messages(chat_id=chat_id, message_ids=message_id, replies=-1)- Raises:¶
ValueError – In case of invalid arguments.: