Hide navigation sidebar
Hide table of contents sidebar
PTB has undergone significant changes in v20. Please read the documentation carefully and also check out the transition guide in the wiki.
Back to top
Toggle table of contents sidebar

# MaybeInaccessibleMessage

class telegram.MaybeInaccessibleMessage(chat, message_id, date, *, api_kwargs=None)

  Bases: `telegram.TelegramObject`

  Base class for Telegram Message Objects.

  Currently, that includes `telegram.Message` and `telegram.InaccessibleMessage`.

  Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their `message_id` and `chat` are equal

  Available In

  - `telegram.CallbackQuery.message`

  - `telegram.Message.pinned_message`

  New in version 20.8.

  Parameters:

    - message_id (`int`) – Unique message identifier.

    - date (`datetime.datetime`) –

      Date the message was sent in Unix time or 0 in Unix time. Converted to `datetime.datetime`

      The default timezone of the bot is used for localization, which is UTC unless `telegram.ext.Defaults.tzinfo` is used.

    - chat (`telegram.Chat`) – Conversation the message belongs to.

  message_id

    Unique message identifier.

    Type:

      `int`

  date

    Date the message was sent in Unix time or 0 in Unix time. Converted to `datetime.datetime`

    The default timezone of the bot is used for localization, which is UTC unless `telegram.ext.Defaults.tzinfo` is used.

    Type:

      `datetime.datetime`

  chat

    Conversation the message belongs to.

    Type:

      `telegram.Chat`

  __bool__()

    Overrides `object.__bool__()` to return the value of `is_accessible`. This is intended to ease migration to Bot API 7.0, as this allows checks like

        if message.pinned_message:
            ...

    to work as before, when `message.pinned_message` was `None`. Note that this does not help with check like

        if message.pinned_message is None:
            ...

    for cases where `message.pinned_message` is now no longer `None`.

    Tip

    Since objects that can only be of type `Message` or `None` are not affected by this change, `Message.__bool__()` is not overridden and will continue to work as before.

    New in version 20.8.

    Deprecated since version 20.8: This behavior is introduced only temporarily to ease migration to Bot API 7.0. It will be removed along with other functionality deprecated by Bot API 7.0.

  classmethod de_json(data, bot)

    See `telegram.TelegramObject.de_json()`.

  property is_accessible

    Convenience attribute. `True`, if the date is not 0 in Unix time.

    New in version 20.8.