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)[source]¶
Bases:
object
Convenience Class to gather all parameters with a (user defined) default value
Changed in version 20.0: Removed the argument and attribute
timeout
. Specify default timeout behavior for the networking backend directly viatelegram.ext.ApplicationBuilder
instead.- Parameters:
parse_mode (
str
, optional) – Mode for parsing entities. Seetelegram.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) – PassTrue
, if the message should be sent even if the specified replied-to message is not found.. Will be used fortelegram.ReplyParameters.allow_sending_without_reply
.If set to
True
, the reply is sent as an actual reply to this message. Ifreply_to_message_id
is passed, this parameter will be ignored. Default:True
in group chats andFalse
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 intzinfo
. If thetelegram.ext.JobQueue
is used, this must be a timezone provided by thepytz
module. Defaults topytz.utc
, if available, anddatetime.timezone.utc
otherwise.block (
bool
, optional) – Default setting for theBaseHandler.block
parameter of handlers and error handlers registered throughApplication.add_handler()
andApplication.add_error_handler()
. Defaults toTrue
.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 oftelegram.Bot.send_message()
,telegram.Bot.edit_message_text()
, andtelegram.InputTextMessageContent
if not specified. If a value is specified for the corresponding parameter, only those parameters oftelegram.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.
If set to
True
, the reply is sent as an actual reply to this message. Ifreply_to_message_id
is passed, this parameter will be ignored. Default:True
in group chats andFalse
in private chats.Added in version 20.8.
- __eq__(other)[source]¶
Defines equality condition for the
Defaults
object. Two objects of this class are considered to be equal if all their parameters are identical.
- __hash__()[source]¶
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[source]¶
Optional. Pass
True
, if the message should be sent even if the specified replied-to message is not found.- Type:
- property block[source]¶
Optional. Default setting for the
BaseHandler.block
parameter of handlers and error handlers registered throughApplication.add_handler()
andApplication.add_error_handler()
.- Type:
- property disable_notification[source]¶
Optional. Sends the message silently. Users will receive a notification with no sound.
- Type:
- property disable_web_page_preview[source]¶
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:
- property do_quote[source]¶
Optional. If set to
True
, the reply is sent as an actual reply to this message. Ifreply_to_message_id
is passed, this parameter will be ignored. Default:True
in group chats andFalse
in private chats.Added in version 20.8.
- Type:
- property explanation_parse_mode[source]¶
Optional. Alias for
parse_mode
, used for the corresponding parameter oftelegram.Bot.send_poll()
.- Type:
- property link_preview_options[source]¶
Optional. Link preview generation options for all outgoing messages.
Added in version 20.8.
- property parse_mode[source]¶
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:
- property protect_content[source]¶
Optional. Protects the contents of the sent message from forwarding and saving.
Added in version 20.0.
- Type:
- property question_parse_mode[source]¶
Optional. Alias for
parse_mode
, used for the corresponding parameter oftelegram.Bot.send_poll()
.Added in version 21.2.
- Type:
- property quote[source]¶
Optional. If set to
True
, the reply is sent as an actual reply to this message. Ifreply_to_message_id
is passed, this parameter will be ignored. Default:True
in group chats andFalse
in private chats.Deprecated since version 20.8: Use
do_quote
instead. This attribute will be removed in future versions.- Type:
- property quote_parse_mode[source]¶
Optional. Alias for
parse_mode
, used for the corresponding parameter oftelegram.ReplyParameters()
.- Type:
- property text_parse_mode[source]¶
Optional. Alias for
parse_mode
, used for the corresponding parameter oftelegram.InputPollOption
.Added in version 21.2.
- Type: