Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# Defaults

final class telegram.ext.Defaults(parse_mode=None, disable_notification=None, disable_web_page_preview=None, quote=None, tzinfo=datetime.timezone.utc, block=True, allow_sending_without_reply=None, protect_content=None, link_preview_options=None, do_quote=None)

  Bases: `object`

  Convenience Class to gather all parameters with a (user defined) default value

  Use In

  `telegram.ext.ApplicationBuilder.defaults()`

  See also

  Architecture Overview, Adding Defaults to Your Bot

  Changed in version 20.0: Removed the argument and attribute `timeout`. Specify default timeout behavior for the networking backend directly via `telegram.ext.ApplicationBuilder` instead.

  Parameters:

    - parse_mode (`str`, optional) – Mode for parsing entities. See `telegram.constants.ParseMode` and formatting options for more details.

    - disable_notification (`bool`, optional) – Sends the message silently. Users will receive a notification with no sound.

    - disable_web_page_preview (`bool`, optional) –

      Disables link previews for links in this message. Mutually exclusive with `link_preview_options`.

      Deprecated since version 20.8: Use `link_preview_options` instead. This parameter will be removed in future versions.

    - allow_sending_without_reply (`bool`, optional) – Pass `True`, if the message should be sent even if the specified replied-to message is not found.. Will be used for `telegram.ReplyParameters.allow_sending_without_reply`.

    - quote (`bool`, optional) –

      If set to `True`, the reply is sent as an actual reply to this message. If `reply_to_message_id` is passed, this parameter will be ignored. Default: `True` in group chats and `False` in private chats.

      Deprecated since version 20.8: Use `do_quote` instead. This parameter will be removed in future versions.

    - tzinfo (`datetime.tzinfo`, optional) –

      A timezone to be used for all date(time) inputs appearing throughout PTB, i.e. if a timezone naive date(time) object is passed somewhere, it will be assumed to be in `tzinfo`. Defaults to `datetime.timezone.utc` otherwise.

      Deprecated since version 21.10: Support for `pytz` timezones is deprecated and will be removed in future versions.

    - block (`bool`, optional) – Default setting for the `BaseHandler.block` parameter of handlers and error handlers registered through `Application.add_handler()` and `Application.add_error_handler()`. Defaults to `True`.

    - protect_content (`bool`, optional) –

      Protects the contents of the sent message from forwarding and saving.

      Added in version 20.0.

    - link_preview_options (`telegram.LinkPreviewOptions`, optional) –

      Link preview generation options for all outgoing messages. Mutually exclusive with `disable_web_page_preview`. This object is used for the corresponding parameter of `telegram.Bot.send_message()`, `telegram.Bot.edit_message_text()`, and `telegram.InputTextMessageContent` if not specified. If a value is specified for the corresponding parameter, only those parameters of `telegram.LinkPreviewOptions` will be overridden that are not explicitly set.

      Example

          from telegram import LinkPreviewOptions
          from telegram.ext import Defaults, ExtBot

          defaults = Defaults(
              link_preview_options=LinkPreviewOptions(show_above_text=True)
          )
          chat_id = 123

          async def main():
              async with ExtBot("Token", defaults=defaults) as bot:
                  # The link preview will be shown above the text.
                  await bot.send_message(chat_id, "https://python-telegram-bot.org")

                  # The link preview will be shown below the text.
                  await bot.send_message(
                      chat_id,
                      "https://python-telegram-bot.org",
                      link_preview_options=LinkPreviewOptions(show_above_text=False)
                  )

                  # The link preview will be shown above the text, but the preview will
                  # show Telegram.
                  await bot.send_message(
                      chat_id,
                      "https://python-telegram-bot.org",
                      link_preview_options=LinkPreviewOptions(url="https://telegram.org")
                  )

      Added in version 20.8.

    - do_quote (`bool`, optional) –

      If set to `True`, the reply is sent as an actual reply to this message. If `reply_to_message_id` is passed, this parameter will be ignored. Default: `True` in group chats and `False` in private chats.

      Added in version 20.8.

  __eq__(other)

    Defines equality condition for the `Defaults` object. Two objects of this class are considered to be equal if all their parameters are identical.

    Returns:

      `True` if both objects have all parameters identical. `False` otherwise.

  __hash__()

    Builds a hash value for this object such that the hash of two objects is equal if and only if the objects are equal in terms of `__eq__()`.

    Returns:

      `int` The hash value of the object.

  property allow_sending_without_reply

    Optional. Pass `True`, if the message should be sent even if the specified replied-to message is not found.

    Type:

      `bool`

  property block

    Optional. Default setting for the `BaseHandler.block` parameter of handlers and error handlers registered through `Application.add_handler()` and `Application.add_error_handler()`.

    Type:

      `bool`

  property disable_notification

    Optional. Sends the message silently. Users will receive a notification with no sound.

    Type:

      `bool`

  property disable_web_page_preview

    Optional. Disables link previews for links in all outgoing messages.

    Deprecated since version 20.8: Use `link_preview_options` instead. This attribute will be removed in future versions.

    Type:

      `bool`

  property do_quote

    Optional. If set to `True`, the reply is sent as an actual reply to this message. If `reply_to_message_id` is passed, this parameter will be ignored. Default: `True` in group chats and `False` in private chats.

    Added in version 20.8.

    Type:

      `bool`

  property explanation_parse_mode

    Optional. Alias for `parse_mode`, used for the corresponding parameter of `telegram.Bot.send_poll()`.

    Type:

      `str`

  property link_preview_options

    Optional. Link preview generation options for all outgoing messages.

    Added in version 20.8.

    Type:

      `telegram.LinkPreviewOptions`

  property parse_mode

    Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or URLs in your bot’s message.

    Type:

      `str`

  property protect_content

    Optional. Protects the contents of the sent message from forwarding and saving.

    Added in version 20.0.

    Type:

      `bool`

  property question_parse_mode

    Optional. Alias for `parse_mode`, used for the corresponding parameter of `telegram.Bot.send_poll()`.

    Added in version 21.2.

    Type:

      `str`

  property quote

    Optional. If set to `True`, the reply is sent as an actual reply to this message. If `reply_to_message_id` is passed, this parameter will be ignored. Default: `True` in group chats and `False` in private chats.

    Deprecated since version 20.8: Use `do_quote` instead. This attribute will be removed in future versions.

    Type:

      `bool`

  property quote_parse_mode

    Optional. Alias for `parse_mode`, used for the corresponding parameter of `telegram.ReplyParameters()`.

    Type:

      `str`

  property text_parse_mode

    Optional. Alias for `parse_mode`, used for the corresponding parameter of `telegram.InputPollOption` and `telegram.Bot.send_gift()`.

    Added in version 21.2.

    Type:

      `str`

  property tzinfo

    A timezone to be used for all date(time) objects appearing throughout PTB.

    Type:

      `tzinfo`