Docs-Python-Telegram-Bot-Org - 22.0 Extrait1
Docs-Python-Telegram-Bot-Org - 22.0 Extrait1
Raises
telegram.error.TelegramError –
async reopenForumTopic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None,
connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for reopen_forum_topic()
async reopenGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None,
connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for reopen_general_forum_topic()
async reopen_forum_topic(chat_id, message_thread_id, *, read_timeout=None,
write_timeout=None, connect_timeout=None, pool_timeout=None,
api_kwargs=None)
Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator
in the chat for this to work and must have can_manage_topics administrator rights, unless it is the
creator of the topic.
Shortcuts
• telegram.Chat.reopen_forum_topic()
• telegram.ChatFullInfo.reopen_forum_topic()
• telegram.Message.reopen_forum_topic()
90 Chapter 6. License
python-telegram-bot Documentation, Release 22.0
Use this method to reopen a closed ‘General’ topic in a forum supergroup chat. The bot must be an
administrator in the chat for this to work and must have can_manage_topics administrator rights.
The topic will be automatically unhidden if it was hidden.
Shortcuts
• telegram.Chat.reopen_general_forum_topic()
• telegram.ChatFullInfo.reopen_general_forum_topic()
Warning
Requests to the Bot API are made by the various methods of this class. This attribute should not
be used manually.
See also
telegram.ChatPermissions.all_permissions()
Shortcuts
92 Chapter 6. License
python-telegram-bot Documentation, Release 22.0
• telegram.Chat.restrict_member()
• telegram.ChatFullInfo.restrict_member()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• user_id (int) – Unique identifier of the target user.
• until_date (int | datetime.datetime, optional) – Date when restrictions will be
lifted for the user, unix time. If user is restricted for more than 366 days or less than
30 seconds from the current time, they are considered to be restricted forever. For
timezone naive datetime.datetime objects, the default timezone of the bot will be
used, which is UTC unless telegram.ext.Defaults.tzinfo is used.
• permissions (telegram.ChatPermissions) – An object for new user permissions.
• use_independent_chat_permissions (bool, optional) – Pass True if chat
permissions are set independently. Otherwise, the can_send_other_messages and
can_add_web_page_previews permissions will imply the can_send_messages,
can_send_audios, can_send_documents, can_send_photos,
can_send_videos, can_send_video_notes, and can_send_voice_notes
permissions; the can_send_polls permission will imply the can_send_messages
permission.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.revoke_invite_link()
• telegram.ChatFullInfo.revoke_invite_link()
94 Chapter 6. License
python-telegram-bot Documentation, Release 22.0
• allow_group_chats (bool, optional) – Pass True if the message can be sent to group
and supergroup chats
• allow_channel_chats (bool, optional) – Pass True if the message can be sent to
channels
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, the prepared message is returned.
Return type
telegram.PreparedInlineMessage
Raises
telegram.error.TelegramError –
async sendAnimation(chat_id, animation, duration=None, width=None, height=None, caption=None,
parse_mode=None, disable_notification=None, reply_markup=None,
caption_entities=None, protect_content=None, message_thread_id=None,
has_spoiler=None, thumbnail=None, reply_parameters=None,
business_connection_id=None, message_effect_id=None,
allow_paid_broadcast=None, show_caption_above_media=None, *,
allow_sending_without_reply=None, reply_to_message_id=None,
filename=None, read_timeout=None, write_timeout=None,
connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for send_animation()
async sendAudio(chat_id, audio, duration=None, performer=None, title=None, caption=None,
disable_notification=None, reply_markup=None, parse_mode=None,
caption_entities=None, protect_content=None, message_thread_id=None,
thumbnail=None, reply_parameters=None, business_connection_id=None,
message_effect_id=None, allow_paid_broadcast=None, *,
allow_sending_without_reply=None, reply_to_message_id=None, filename=None,
read_timeout=None, write_timeout=None, connect_timeout=None,
pool_timeout=None, api_kwargs=None)
Alias for send_audio()
async sendChatAction(chat_id, action, message_thread_id=None, business_connection_id=None, *,
read_timeout=None, write_timeout=None, connect_timeout=None,
pool_timeout=None, api_kwargs=None)
Alias for send_chat_action()
96 Chapter 6. License
python-telegram-bot Documentation, Release 22.0
98 Chapter 6. License
python-telegram-bot Documentation, Release 22.0
Note
thumbnail will be ignored for small files, for which Telegram can easily generate thumbnails.
However, this behaviour is undocumented and might be changed by Telegram.
See also
Shortcuts
• telegram.Chat.send_animation()
• telegram.ChatFullInfo.send_animation()
• telegram.Message.reply_animation()
• telegram.User.send_animation()
Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• animation (str | file object | InputFile | bytes | pathlib.Path | telegram.
Animation) – Animation to send. Pass a file_id as String to send a file that exists
on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram
to get a file from the Internet, or upload a new one. To upload a file, you can either pass
a file object (e.g. open("filename", "rb")), the file contents as bytes or the path
of the file (as string or pathlib.Path object). In the latter case, the file contents will
either be read as bytes or the file path will be passed to Telegram, depending on the
local_mode setting. Lastly you can pass an existing telegram.Animation object
to send.
Changed in version 13.2: Accept bytes as input.
• duration (int | datetime.timedelta, optional) – Duration of sent animation in
seconds.
Changed in version 21.11: datetime.timedelta objects are accepted in addition to
plain int values.
• width (int, optional) – Animation width.
See also
Shortcuts
• telegram.Chat.send_audio()
• telegram.ChatFullInfo.send_audio()
• telegram.Message.reply_audio()
• telegram.User.send_audio()
Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• audio (str | file object | InputFile | bytes | pathlib.Path | telegram.Audio) –
Audio file to send. Pass a file_id as String to send a file that exists on the Telegram
servers (recommended), pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one. To upload a file, you can either pass a file object
(e.g. open("filename", "rb")), the file contents as bytes or the path of the file (as
string or pathlib.Path object). In the latter case, the file contents will either be read
as bytes or the file path will be passed to Telegram, depending on the local_mode
setting. Lastly you can pass an existing telegram.Audio object to send.
Changed in version 13.2: Accept bytes as input.
Changed in version 20.0: File paths as input is also accepted for bots not running in
local_mode.
• caption (str, optional) – Audio caption, 0-1024 characters after entities parsing.
• parse_mode (str, optional) – Mode for parsing entities. See telegram.
constants.ParseMode and formatting options for more details.
• caption_entities (Sequence[telegram.MessageEntity], optional) – Sequence
of special entities that appear in the caption, which can be specified instead of
parse_mode.
Changed in version 20.0: Accepts any collections.abc.Sequence as input instead
of just a list.
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• filename (str, optional) – Custom file name for the audio, when uploading a new
file. Convenience parameter, useful e.g. when sending files generated by the tempfile
module.
Added in version 13.1.
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. By default, 20 seconds are used as write time-
out.
Changed in version 22.0: The default value changed to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, the sent Message is returned.
Return type
telegram.Message
Raises
telegram.error.TelegramError –
async send_chat_action(chat_id, action, message_thread_id=None, business_connection_id=None,
*, read_timeout=None, write_timeout=None, connect_timeout=None,
pool_timeout=None, api_kwargs=None)
Use this method when you need to tell the user that something is happening on the bot’s side. The
status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its
typing status). Telegram only recommends using this method when a response from the bot will take
a noticeable amount of time to arrive.
Shortcuts
• telegram.Chat.send_action()
• telegram.Chat.send_chat_action()
• telegram.ChatFullInfo.send_action()
• telegram.ChatFullInfo.send_chat_action()
• telegram.Message.reply_chat_action()
• telegram.User.send_action()
• telegram.User.send_chat_action()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• action (str) – Type of action to broadcast. Choose one, depending on what the user
is about to receive. For convenience look at the constants in telegram.constants.
ChatAction.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
Note
You can either supply contact or phone_number and first_name with optionally last_name
and optionally vcard.
Shortcuts
• telegram.Chat.send_contact()
• telegram.ChatFullInfo.send_contact()
• telegram.Message.reply_contact()
• telegram.User.send_contact()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• phone_number (str, optional) – Contact’s phone number.
• first_name (str, optional) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• vcard (str, optional) – Additional data about the contact in the form of a vCard,
0-2048 bytes.
• disable_notification (bool, optional) – Sends the message silently. Users will
receive a notification with no sound.
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup |
ReplyKeyboardRemove | ForceReply, optional) – Additional interface op-
tions. An object for an inline keyboard, custom reply keyboard, instructions to remove
reply keyboard or to force a reply from the user.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
• message_effect_id (str, optional) – Unique identifier of the message effect to be
added to the message; for private chats only.
Added in version 21.3.
• allow_paid_broadcast (bool, optional) – Pass True to allow up to 1000 messages
per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message.
The relevant Stars will be withdrawn from the bot’s balance.
Added in version 21.7.
Keyword Arguments
• allow_sending_without_reply (bool, optional) – Pass True, if the message
should be sent even if the specified replied-to message is not found. Mutually exclusive
with reply_parameters, which this is a convenience parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• contact (telegram.Contact, optional) – The contact to send.
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, the sent Message is returned.
Return type
telegram.Message
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.send_dice()
• telegram.ChatFullInfo.send_dice()
• telegram.Message.reply_dice()
• telegram.User.send_dice()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• disable_notification (bool, optional) – Sends the message silently. Users will
receive a notification with no sound.
• reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup |
ReplyKeyboardRemove | ForceReply, optional) – Additional interface op-
tions. An object for an inline keyboard, custom reply keyboard, instructions to remove
reply keyboard or to force a reply from the user
• emoji (str, optional) – Emoji on which the dice throw animation is based. Currently,
must be one of telegram.constants.DiceEmoji. Dice can have values 1-6 for '',
'' and '', values 1-5 for '' and '', and values 1- 64 for ''. Defaults to ''.
Changed in version 13.4: Added the '' emoji.
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
• message_effect_id (str, optional) – Unique identifier of the message effect to be
added to the message; for private chats only.
Added in version 21.3.
• allow_paid_broadcast (bool, optional) – Pass True to allow up to 1000 messages
per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message.
The relevant Stars will be withdrawn from the bot’s balance.
Added in version 21.7.
Keyword Arguments
• allow_sending_without_reply (bool, optional) – Pass True, if the message
should be sent even if the specified replied-to message is not found. Mutually exclusive
with reply_parameters, which this is a convenience parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
See also
Shortcuts
• telegram.Chat.send_document()
• telegram.ChatFullInfo.send_document()
• telegram.Message.reply_document()
• telegram.User.send_document()
Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• document (str | file object | InputFile | bytes | pathlib.Path | telegram.
Document) – File to send. Pass a file_id as String to send a file that exists on the
Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get
a file from the Internet, or upload a new one. To upload a file, you can either pass a
file object (e.g. open("filename", "rb")), the file contents as bytes or the path of
the file (as string or pathlib.Path object). In the latter case, the file contents will
either be read as bytes or the file path will be passed to Telegram, depending on the
local_mode setting. Lastly you can pass an existing telegram.Document object to
send.
Note
Sending by URL will currently only work GIF, PDF & ZIP files.
Shortcuts
• telegram.Chat.send_game()
• telegram.ChatFullInfo.send_game()
• telegram.Message.reply_game()
• telegram.User.send_game()
Parameters
• chat_id (int) – Unique identifier for the target chat.
• game_short_name (str) – Short name of the game, serves as the unique identifier for
the game. Set up your games via @BotFather.
• disable_notification (bool, optional) – Sends the message silently. Users will
receive a notification with no sound.
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_markup (telegram.InlineKeyboardMarkup, optional) – An object for a
new inline keyboard. If empty, one “Play game_title” button will be shown. If not
empty, the first button must launch the game.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
• message_effect_id (str, optional) – Unique identifier of the message effect to be
added to the message; for private chats only.
Added in version 21.3.
• allow_paid_broadcast (bool, optional) – Pass True to allow up to 1000 messages
per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message.
The relevant Stars will be withdrawn from the bot’s balance.
Added in version 21.7.
Keyword Arguments
Shortcuts
• telegram.Chat.send_gift()
• telegram.ChatFullInfo.send_gift()
• telegram.User.send_gift()
Warning
As of API 5.2 start_parameter is an optional argument and therefore the order of the arguments
had to be changed. Use keyword arguments to make sure that the arguments are passed correctly.
Shortcuts
• telegram.Chat.send_invoice()
• telegram.ChatFullInfo.send_invoice()
• telegram.Message.reply_invoice()
• telegram.User.send_invoice()
Changed in version 13.5: As of Bot API 5.2, the parameter start_parameter is optional.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• title (str) – Product name. 1- 32 characters.
• description (str) – Product description. 1- 255 characters.
• payload (str) – Bot-defined invoice payload. 1- 128 bytes. This will not be displayed
to the user, use it for your internal processes.
• provider_token (str, optional) – Payments provider token, obtained via @BotFa-
ther. Pass an empty string for payments in Telegram Stars.
Changed in version 21.11: Bot API 7.4 made this parameter is optional and this is now
reflected in the function signature.
• currency (str) – Three-letter ISO 4217 currency code, see more on currencies. Pass
XTR for payment in Telegram Stars.
• prices (Sequence[telegram.LabeledPrice]) – Price breakdown, a sequence of
components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
Must contain exactly one item for payment in Telegram Stars.
Changed in version 20.0: Accepts any collections.abc.Sequence as input instead
of just a list.
• max_tip_amount (int, optional) – The maximum accepted amount for tips in the
smallest units of the currency (integer, not float/double). For example, for a maximum
tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in curren-
cies.json, it shows the number of digits past the decimal point for each currency (2 for
the majority of currencies). Defaults to 0. Not supported for payment in Telegram
Stars.
Added in version 13.5.
• suggested_tip_amounts (Sequence[int], optional) – An array of suggested
amounts of tips in the smallest units of the currency (integer, not float/double). At
most 4 suggested tip amounts can be specified. The suggested tip amounts must be
positive, passed in a strictly increased order and must not exceed max_tip_amount.
Added in version 13.5.
Note
Shortcuts
• telegram.Chat.send_location()
• telegram.ChatFullInfo.send_location()
• telegram.Message.reply_location()
• telegram.User.send_location()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• latitude (float, optional) – Latitude of location.
• longitude (float, optional) – Longitude of location.
• horizontal_accuracy (int, optional) – The radius of uncertainty for the location,
measured in meters; 0-1500.
• live_period (int | datetime.timedelta, optional) – Period in seconds for which
the location will be updated, should be between 60 and 86400, or 2147483647 for
live locations that can be edited indefinitely.
Changed in version 21.11: datetime.timedelta objects are accepted in addition to
plain int values.
• heading (int, optional) – For live locations, a direction in which the user is moving,
in degrees. Must be between 1 and 360 if specified.
• proximity_alert_radius (int, optional) – For live locations, a maximum distance
for proximity alerts about approaching another chat member, in meters. Must be be-
tween 1 and 100000 if specified.
• disable_notification (bool, optional) – Sends the message silently. Users will
receive a notification with no sound.
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup |
ReplyKeyboardRemove | ForceReply, optional) – Additional interface op-
tions. An object for an inline keyboard, custom reply keyboard, instructions to remove
reply keyboard or to force a reply from the user.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Use this method to send a group of photos, videos, documents or audios as an album. Documents and
audio files can be only grouped in an album with messages of the same type.
Note
If you supply a caption (along with either parse_mode or caption_entities), then items in
media must have no captions, and vice versa.
See also
Shortcuts
• telegram.Chat.send_media_group()
• telegram.ChatFullInfo.send_media_group()
• telegram.Message.reply_media_group()
• telegram.User.send_media_group()
Return type
tuple[telegram.Message]
Raises
telegram.error.TelegramError –
async send_message(chat_id, text, parse_mode=None, entities=None, disable_notification=None,
protect_content=None, reply_markup=None, message_thread_id=None,
link_preview_options=None, reply_parameters=None,
business_connection_id=None, message_effect_id=None,
allow_paid_broadcast=None, *, allow_sending_without_reply=None,
reply_to_message_id=None, disable_web_page_preview=None,
read_timeout=None, write_timeout=None, connect_timeout=None,
pool_timeout=None, api_kwargs=None)
Use this method to send text messages.
Shortcuts
• telegram.Chat.send_message()
• telegram.ChatFullInfo.send_message()
• telegram.Message.reply_html()
• telegram.Message.reply_markdown_v2()
• telegram.Message.reply_markdown()
• telegram.Message.reply_text()
• telegram.User.send_message()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• text (str) – Text of the message to be sent. Max 4096 characters after entities pars-
ing.
• parse_mode (str) – Mode for parsing entities. See telegram.constants.
ParseMode and formatting options for more details.
• entities (Sequence[telegram.MessageEntity], optional) – Sequence of special
entities that appear in message text, which can be specified instead of parse_mode.
Changed in version 20.0: Accepts any collections.abc.Sequence as input instead
of just a list.
• link_preview_options (LinkPreviewOptions, optional) – Link preview genera-
tion options for the message. Mutually exclusive with disable_web_page_preview.
Added in version 20.8.
• disable_notification (bool, optional) – Sends the message silently. Users will
receive a notification with no sound.
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup |
ReplyKeyboardRemove | ForceReply, optional) – Additional interface op-
tions. An object for an inline keyboard, custom reply keyboard, instructions to remove
reply keyboard or to force a reply from the user.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
• message_effect_id (str, optional) – Unique identifier of the message effect to be
added to the message; for private chats only.
Added in version 21.3.
• allow_paid_broadcast (bool, optional) – Pass True to allow up to 1000 messages
per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message.
The relevant Stars will be withdrawn from the bot’s balance.
Added in version 21.7.
Keyword Arguments
• allow_sending_without_reply (bool, optional) – Pass True, if the message
should be sent even if the specified replied-to message is not found. Mutually exclusive
with reply_parameters, which this is a convenience parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• disable_web_page_preview (bool, optional) – Disables link previews for links in
this message. Convenience parameter for setting link_preview_options. Mutually
exclusive with link_preview_options.
Changed in version 20.8: Bot API 7.0 introduced link_preview_options replac-
ing this argument. PTB will automatically convert this argument to that one, but for
advanced options, please use link_preview_options directly.
Changed in version 21.0: This argument is now a keyword-only argument.
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
Shortcuts
• telegram.Chat.send_paid_media()
• telegram.ChatFullInfo.send_paid_media()
• telegram.Message.reply_paid_media()
See also
Shortcuts
• telegram.Chat.send_photo()
• telegram.ChatFullInfo.send_photo()
• telegram.Message.reply_photo()
• telegram.User.send_photo()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• photo (str | file object | InputFile | bytes | pathlib.Path | telegram.
PhotoSize) – Photo to send. Pass a file_id as String to send a file that exists on
the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to
get a file from the Internet, or upload a new one. To upload a file, you can either pass
a file object (e.g. open("filename", "rb")), the file contents as bytes or the path
of the file (as string or pathlib.Path object). In the latter case, the file contents will
either be read as bytes or the file path will be passed to Telegram, depending on the
local_mode setting. Lastly you can pass an existing telegram.PhotoSize object
to send.
Caution
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup |
ReplyKeyboardRemove | ForceReply, optional) – Additional interface op-
tions. An object for an inline keyboard, custom reply keyboard, instructions to remove
reply keyboard or to force a reply from the user.
• has_spoiler (bool, optional) – Pass True if the photo needs to be covered with a
spoiler animation.
Added in version 20.0.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
• message_effect_id (str, optional) – Unique identifier of the message effect to be
added to the message; for private chats only.
Added in version 21.3.
• allow_paid_broadcast (bool, optional) – Pass True to allow up to 1000 messages
per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message.
The relevant Stars will be withdrawn from the bot’s balance.
Added in version 21.7.
• show_caption_above_media (bool, optional) – Pass True, if the caption must be
shown above the message media.
Added in version 21.3.
Keyword Arguments
• allow_sending_without_reply (bool, optional) – Pass True, if the message
should be sent even if the specified replied-to message is not found. Mutually exclusive
with reply_parameters, which this is a convenience parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• filename (str, optional) – Custom file name for the photo, when uploading a new
file. Convenience parameter, useful e.g. when sending files generated by the tempfile
module.
Added in version 13.1.
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. By default, 20 seconds are used as write time-
out.
Changed in version 22.0: The default value changed to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, the sent Message is returned.
Return type
telegram.Message
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.send_poll()
• telegram.ChatFullInfo.send_poll()
• telegram.Message.reply_poll()
• telegram.User.send_poll()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• question (str) – Poll question, 1- 300 characters.
• options (Sequence[str | telegram.InputPollOption]) – Sequence of 2- 10 an-
swer options. Each option may either be a string with 1- 100 characters or an
Returns
On success, the sent Message is returned.
Return type
telegram.Message
Raises
telegram.error.TelegramError –
See also
Shortcuts
• telegram.Chat.send_sticker()
• telegram.ChatFullInfo.send_sticker()
• telegram.Message.reply_sticker()
• telegram.User.send_sticker()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• sticker (str | file object | InputFile | bytes | pathlib.Path | telegram.
Sticker) – Sticker to send. Pass a file_id as String to send a file that exists on
the Telegram servers (recommended), pass an HTTP URL as a String for Telegram
to get a file from the Internet, or upload a new one. To upload a file, you can either
pass a file object (e.g. open("filename", "rb")), the file contents as bytes or the
path of the file (as string or pathlib.Path object). In the latter case, the file contents
will either be read as bytes or the file path will be passed to Telegram, depending on
the local_mode setting. Video stickers can only be sent by a file_id. Video and
animated stickers can’t be sent via an HTTP URL.
Lastly you can pass an existing telegram.Sticker object to send.
Changed in version 13.2: Accept bytes as input.
Changed in version 20.0: File paths as input is also accepted for bots not running in
local_mode.
• emoji (str, optional) – Emoji associated with the sticker; only for just uploaded stick-
ers
Added in version 20.2.
• disable_notification (bool, optional) – Sends the message silently. Users will
receive a notification with no sound.
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup |
ReplyKeyboardRemove | ForceReply, optional) – Additional interface op-
tions. An object for an inline keyboard, custom reply keyboard, instructions to remove
reply keyboard or to force a reply from the user.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
• message_effect_id (str, optional) – Unique identifier of the message effect to be
added to the message; for private chats only.
Added in version 21.3.
• allow_paid_broadcast (bool, optional) – Pass True to allow up to 1000 messages
per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message.
The relevant Stars will be withdrawn from the bot’s balance.
Added in version 21.7.
Keyword Arguments
• allow_sending_without_reply (bool, optional) – Pass True, if the message
should be sent even if the specified replied-to message is not found. Mutually exclusive
with reply_parameters, which this is a convenience parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. By default, 20 seconds are used as write time-
out.
Changed in version 22.0: The default value changed to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
Note
• You can either supply venue, or latitude, longitude, title and address and op-
tionally foursquare_id and foursquare_type or optionally google_place_id and
google_place_type.
• Foursquare details and Google Place details are mutually exclusive. However, this behaviour
is undocumented and might be changed by Telegram.
Shortcuts
• telegram.Chat.send_venue()
• telegram.ChatFullInfo.send_venue()
• telegram.Message.reply_venue()
• telegram.User.send_venue()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• latitude (float, optional) – Latitude of venue.
• longitude (float, optional) – Longitude of venue.
• title (str, optional) – Name of the venue.
• address (str, optional) – Address of the venue.
• foursquare_id (str, optional) – Foursquare identifier of the venue.
Note
thumbnail will be ignored for small video files, for which Telegram can easily generate thumb-
nails. However, this behaviour is undocumented and might be changed by Telegram.
See also
Shortcuts
• telegram.Chat.send_video()
• telegram.ChatFullInfo.send_video()
• telegram.Message.reply_video()
• telegram.User.send_video()
Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• video (str | file object | InputFile | bytes | pathlib.Path | telegram.Video) –
Video file to send. Pass a file_id as String to send a file that exists on the Telegram
servers (recommended), pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one. To upload a file, you can either pass a file object
(e.g. open("filename", "rb")), the file contents as bytes or the path of the file (as
string or pathlib.Path object). In the latter case, the file contents will either be read
as bytes or the file path will be passed to Telegram, depending on the local_mode
setting. Lastly you can pass an existing telegram.Video object to send.
Changed in version 13.2: Accept bytes as input.
Changed in version 20.0: File paths as input is also accepted for bots not running in
local_mode.
• duration (int | datetime.timedelta, optional) – Duration of sent video in sec-
onds.
Changed in version 21.11: datetime.timedelta objects are accepted in addition to
plain int values.
• width (int, optional) – Video width.
• height (int, optional) – Video height.
• cover (file object | bytes | pathlib.Path | str, optional) – Cover for the video
in the message. Pass a file_id as String to send a file that exists on the Telegram
servers (recommended), pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one. To upload a file, you can either pass a file object
(e.g. open("filename", "rb")) or the file contents as bytes. If the bot is running
in local_mode, passing the path of the file (as string or pathlib.Path object) is
supported as well.
Added in version 21.11.
• start_timestamp (int, optional) – Start timestamp for the video in the message.
Added in version 21.11.
• caption (str, optional) – Video caption (may also be used when resending videos
by file_id), 0-1024 characters after entities parsing.
• parse_mode (str, optional) – Mode for parsing entities. See telegram.
constants.ParseMode and formatting options for more details.
• caption_entities (Sequence[telegram.MessageEntity], optional) – Sequence
of special entities that appear in the caption, which can be specified instead of
parse_mode.
Changed in version 20.0: Accepts any collections.abc.Sequence as input instead
of just a list.
• supports_streaming (bool, optional) – Pass True, if the uploaded video is suitable
for streaming.
• disable_notification (bool, optional) – Sends the message silently. Users will
receive a notification with no sound.
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup |
ReplyKeyboardRemove | ForceReply, optional) – Additional interface op-
tions. An object for an inline keyboard, custom reply keyboard, instructions to remove
reply keyboard or to force a reply from the user.
• has_spoiler (bool, optional) – Pass True if the video needs to be covered with a
spoiler animation.
Added in version 20.0.
• thumbnail (file object | bytes | pathlib.Path | str, optional) – Thumbnail of the
file sent; can be ignored if thumbnail generation for the file is supported server-side.
The thumbnail should be in JPEG format and less than 200 kB in size. A thumb-
nail’s width and height should not exceed 320. Ignored if the file is not uploaded
using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a
new file. To upload a file, you can either pass a file object (e.g. open("filename",
"rb")), the file contents as bytes or the path of the file (as string or pathlib.Path
object). In the latter case, the file contents will either be read as bytes or the file path
will be passed to Telegram, depending on the local_mode setting.
Added in version 20.2.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
• message_effect_id (str, optional) – Unique identifier of the message effect to be
added to the message; for private chats only.
Added in version 21.3.
• allow_paid_broadcast (bool, optional) – Pass True to allow up to 1000 messages
per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message.
The relevant Stars will be withdrawn from the bot’s balance.
Added in version 21.7.
• show_caption_above_media (bool, optional) – Pass True, if the caption must be
shown above the message media.
Added in version 21.3.
Keyword Arguments
• allow_sending_without_reply (bool, optional) – Pass True, if the message
should be sent even if the specified replied-to message is not found. Mutually exclusive
with reply_parameters, which this is a convenience parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• filename (str, optional) – Custom file name for the video, when uploading a new
file. Convenience parameter, useful e.g. when sending files generated by the tempfile
module.
Added in version 13.1.
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. By default, 20 seconds are used as write time-
out.
Changed in version 22.0: The default value changed to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, the sent Message is returned.
Return type
telegram.Message
Raises
telegram.error.TelegramError –
async send_video_note(chat_id, video_note, duration=None, length=None,
disable_notification=None, reply_markup=None, protect_content=None,
message_thread_id=None, thumbnail=None, reply_parameters=None,
business_connection_id=None, message_effect_id=None,
allow_paid_broadcast=None, *, allow_sending_without_reply=None,
reply_to_message_id=None, filename=None, read_timeout=None,
write_timeout=None, connect_timeout=None, pool_timeout=None,
api_kwargs=None)
As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this
method to send video messages.
Note
thumbnail will be ignored for small video files, for which Telegram can easily generate thumb-
nails. However, this behaviour is undocumented and might be changed by Telegram.
See also
Shortcuts
• telegram.Chat.send_video_note()
• telegram.ChatFullInfo.send_video_note()
• telegram.Message.reply_video_note()
• telegram.User.send_video_note()
Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• video_note (str | file object | InputFile | bytes | pathlib.Path | telegram.
VideoNote) – Video note to send. Pass a file_id as String to send a video note
that exists on the Telegram servers (recommended) or upload a new video us-
ing multipart/form-data. To upload a file, you can either pass a file object (e.g.
open("filename", "rb")), the file contents as bytes or the path of the file (as string
or pathlib.Path object). In the latter case, the file contents will either be read as
bytes or the file path will be passed to Telegram, depending on the local_mode set-
ting. Lastly you can pass an existing telegram.VideoNote object to send. Sending
video notes by a URL is currently unsupported.
Changed in version 13.2: Accept bytes as input.
Changed in version 20.0: File paths as input is also accepted for bots not running in
local_mode.
• duration (int | datetime.timedelta, optional) – Duration of sent video in sec-
onds.
Changed in version 21.11: datetime.timedelta objects are accepted in addition to
plain int values.
• length (int, optional) – Video width and height, i.e. diameter of the video message.
• disable_notification (bool, optional) – Sends the message silently. Users will
receive a notification with no sound.
• protect_content (bool, optional) – Protects the contents of the sent message from
forwarding and saving.
Added in version 13.10.
• message_thread_id (int, optional) – Unique identifier for the target message thread
(topic) of the forum; for forum supergroups only.
Added in version 20.0.
• reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup |
ReplyKeyboardRemove | ForceReply, optional) – Additional interface op-
tions. An object for an inline keyboard, custom reply keyboard, instructions to remove
reply keyboard or to force a reply from the user.
• thumbnail (file object | bytes | pathlib.Path | str, optional) – Thumbnail of the
file sent; can be ignored if thumbnail generation for the file is supported server-side.
The thumbnail should be in JPEG format and less than 200 kB in size. A thumb-
nail’s width and height should not exceed 320. Ignored if the file is not uploaded
using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a
new file. To upload a file, you can either pass a file object (e.g. open("filename",
"rb")), the file contents as bytes or the path of the file (as string or pathlib.Path
object). In the latter case, the file contents will either be read as bytes or the file path
will be passed to Telegram, depending on the local_mode setting.
Added in version 20.2.
• reply_parameters (telegram.ReplyParameters, optional) – Description of the
message to reply to.
Added in version 20.8.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be sent.
Added in version 21.1.
• message_effect_id (str, optional) – Unique identifier of the message effect to be
added to the message; for private chats only.
Added in version 21.3.
• allow_paid_broadcast (bool, optional) – Pass True to allow up to 1000 messages
per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message.
The relevant Stars will be withdrawn from the bot’s balance.
Added in version 21.7.
Keyword Arguments
• allow_sending_without_reply (bool, optional) – Pass True, if the message
should be sent even if the specified replied-to message is not found. Mutually exclusive
with reply_parameters, which this is a convenience parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• filename (str, optional) – Custom file name for the video note, when uploading
a new file. Convenience parameter, useful e.g. when sending files generated by the
tempfile module.
Added in version 13.1.
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. By default, 20 seconds are used as write time-
out.
Changed in version 22.0: The default value changed to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
Note
To use this method, the file must have the type audio/ogg and be no more than 1 MB in size. 1
MB- 20 MB voice notes will be sent as files.
See also
Shortcuts
• telegram.Chat.send_voice()
• telegram.ChatFullInfo.send_voice()
• telegram.Message.reply_voice()
• telegram.User.send_voice()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• voice (str | file object | InputFile | bytes | pathlib.Path | telegram.Voice) –
Voice file to send. Pass a file_id as String to send a file that exists on the Telegram
servers (recommended), pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one. To upload a file, you can either pass a file object
(e.g. open("filename", "rb")), the file contents as bytes or the path of the file (as
string or pathlib.Path object). In the latter case, the file contents will either be read
as bytes or the file path will be passed to Telegram, depending on the local_mode
setting. Lastly you can pass an existing telegram.Voice object to send.
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• reply_to_message_id (int, optional) – If the message is a reply, ID of the original
message. Mutually exclusive with reply_parameters, which this is a convenience
parameter for
Changed in version 20.8: Bot API 7.0 introduced reply_parameters replacing this
argument. PTB will automatically convert this argument to that one, but you should
update your code to use the new argument.
Changed in version 21.0: This argument is now a keyword-only argument.
• filename (str, optional) – Custom file name for the voice, when uploading a new file.
Convenience parameter, useful e.g. when sending files generated by the tempfile
module.
Added in version 13.1.
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. By default, 20 seconds are used as write time-
out.
Changed in version 22.0: The default value changed to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, the sent Message is returned.
Return type
telegram.Message
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.set_administrator_custom_title()
• telegram.ChatFullInfo.set_administrator_custom_title()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• user_id (int) – Unique identifier of the target administrator.
• custom_title (str) – New custom title for the administrator; 0-16 characters, emoji
are not allowed.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.set_description()
• telegram.ChatFullInfo.set_description()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• description (str, optional) – New chat description, 0-255 characters.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
See also
Shortcuts
• telegram.Chat.set_menu_button()
• telegram.ChatFullInfo.set_menu_button()
• telegram.User.set_menu_button()
group or a supergroup for this to work and must have the telegram.ChatMemberAdministrator.
can_restrict_members admin rights.
Shortcuts
• telegram.Chat.set_permissions()
• telegram.ChatFullInfo.set_permissions()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• permissions (telegram.ChatPermissions) – New default chat permissions.
• use_independent_chat_permissions (bool, optional) – Pass True if chat
permissions are set independently. Otherwise, the can_send_other_messages and
can_add_web_page_previews permissions will imply the can_send_messages,
can_send_audios, can_send_documents, can_send_photos,
can_send_videos, can_send_video_notes, and can_send_voice_notes
permissions; the can_send_polls permission will imply the can_send_messages
permission.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.set_photo()
• telegram.ChatFullInfo.set_photo()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• photo (file object | bytes | pathlib.Path) – New chat photo. To upload a file, you
can either pass a file object (e.g. open("filename", "rb")), the file contents as
bytes or the path of the file (as string or pathlib.Path object). In the latter case, the
file contents will either be read as bytes or the file path will be passed to Telegram,
depending on the local_mode setting.
Changed in version 13.2: Accept bytes as input.
Changed in version 20.0: File paths as input is also accepted for bots not running in
local_mode.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. By default, 20 seconds are used as write time-
out.
Changed in version 22.0: The default value changed to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.set_title()
• telegram.ChatFullInfo.set_title()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• title (str) – New chat title, 1- 128 characters.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
Use this method to set the thumbnail of a custom emoji sticker set.
Added in version 20.2.
Parameters
• name (str) – Sticker set name.
• custom_emoji_id (str, optional) – Custom emoji identifier of a sticker from the
sticker set; pass an empty string to drop the thumbnail and use the first sticker as the
thumbnail.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
async set_game_score(user_id, score, chat_id=None, message_id=None, inline_message_id=None,
force=None, disable_edit_message=None, *, read_timeout=None,
write_timeout=None, connect_timeout=None, pool_timeout=None,
api_kwargs=None)
Use this method to set the score of the specified user in a game message.
See also
telegram.Game.text
Shortcuts
• telegram.CallbackQuery.set_game_score()
• telegram.Message.set_game_score()
Parameters
• user_id (int) – User identifier.
• score (int) – New score, must be non-negative.
• force (bool, optional) – Pass True, if the high score is allowed to decrease. This can
be useful when fixing mistakes or banning cheaters.
Shortcuts
• telegram.Chat.set_message_reaction()
• telegram.ChatFullInfo.set_message_reaction()
• telegram.Message.set_reaction()
Tip
• is_big (bool, optional) – Pass True to set the reaction with a big animation.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
bool On success, True is returned.
Raises
telegram.error.TelegramError –
async set_my_commands(commands, scope=None, language_code=None, *, read_timeout=None,
write_timeout=None, connect_timeout=None, pool_timeout=None,
api_kwargs=None)
Use this method to change the list of the bot’s commands. See the Telegram docs for more details about
bot commands.
See also
get_my_commands(), delete_my_commands()
Parameters
• commands (Sequence[BotCommand | (str, str)]) – A sequence of bot commands to
be set as the list of the bot’s commands. At most 100 commands can be specified.
Note
If you pass in a sequence of tuple, the order of elements in each tuple must
correspond to the order of positional arguments to create a BotCommand instance.
See also
get_my_default_administrator_rights()
Caution
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
async set_sticker_set_thumbnail(name, user_id, format, thumbnail=None, *, read_timeout=None,
write_timeout=None, connect_timeout=None,
pool_timeout=None, api_kwargs=None)
Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file
must match the format of the stickers in the set.
Added in version 20.2.
Changed in version 21.1: As per Bot API 7.2, the new argument format will be required, and thus the
order of the arguments had to be changed.
Parameters
• name (str) – Sticker set name
• user_id (int) – User identifier of created sticker set owner.
• format (str) – Format of the added sticker, must be one of 'static' for a .WEBP or
.PNG image, 'animated' for a .TGS animation, 'video' for a .WEBM video.
Added in version 21.1.
• thumbnail (str | file object | InputFile | bytes | pathlib.Path, optional) – A
.WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and
have width and height of exactly 100 px, or a .TGS animation with the thumbnail up
to 32 kilobytes in size; see the docs for animated sticker technical requirements, or a
.WEBM video with the thumbnail up to 32 kilobytes in size; see this for video sticker
technical requirements.
Pass a file_id as String to send a file that exists on the Telegram servers (recom-
mended), pass an HTTP URL as a String for Telegram to get a file from the Inter-
net, or upload a new one. To upload a file, you can either pass a file object (e.g.
open("filename", "rb")), the file contents as bytes or the path of the file (as string
or pathlib.Path object). In the latter case, the file contents will either be read as
bytes or the file path will be passed to Telegram, depending on the local_mode set-
ting.
Animated and video sticker set thumbnails can’t be uploaded via HTTP URL. If omit-
ted, then the thumbnail is dropped and the first sticker is used as the thumbnail.
Keyword Arguments
Note
1. You will not be able to receive updates using get_updates() for long as an outgoing web-
hook is set up.
2. To use a self-signed certificate, you need to upload your public key certificate using
certificate parameter. Please upload as InputFile, sending a String will not work.
3. Ports currently supported for Webhooks: telegram.constants.
SUPPORTED_WEBHOOK_PORTS.
If you’re having any trouble setting up webhooks, please check out this guide to Webhooks.
See also
telegram.ext.Application.run_webhook(), telegram.ext.Updater.
start_webhook()
Examples
Parameters
• url (str) – HTTPS url to send updates to. Use an empty string to remove webhook
integration.
• certificate (file object | bytes | pathlib.Path | str) – Upload your public key
certificate so that the root certificate in use can be checked. See our self-signed guide
for details. To upload a file, you can either pass a file object (e.g. open("filename",
"rb")) or the file contents as bytes. If the bot is running in local_mode, passing the
path of the file (as string or pathlib.Path object) is supported as well.
• ip_address (str, optional) – The fixed IP address which will be used to send web-
hook requests instead of the IP address resolved through DNS.
• max_connections (int, optional) – Maximum allowed number of simultaneous
HTTPS connections to the webhook for update delivery, 1- 100. Defaults to 40. Use
lower values to limit the load on your bot’s server, and higher values to increase your
bot’s throughput.
• allowed_updates (Sequence[str], optional) – A sequence of the types of
updates you want your bot to receive. For example, specify [“message”,
“edited_channel_post”, “callback_query”] to only receive updates of these types. See
telegram.Update for a complete list of available update types. Specify an empty se-
quence to receive all updates except telegram.Update.chat_member, telegram.
Update.message_reaction and telegram.Update.message_reaction_count
(default). If not specified, the previous setting will be used. Please note that this pa-
rameter doesn’t affect updates created before the call to the set_webhook, so unwanted
update may be received for a short period of time.
Changed in version 20.0: Accepts any collections.abc.Sequence as input instead
of just a list.
• drop_pending_updates (bool, optional) – Pass True to drop all pending updates.
• secret_token (str, optional) – A secret token to be sent in a header
X-Telegram-Bot-Api-Secret-Token in every webhook request, 1- 256 characters.
Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure
that the request comes from a webhook set by you.
Added in version 20.0.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
async shutdown()
Stop & clear resources used by this class. Currently just calls telegram.request.BaseRequest.
shutdown() for the request objects used by this bot.
See also
initialize()
Shortcuts
• telegram.CallbackQuery.stop_message_live_location()
• telegram.Message.stop_live_location()
Parameters
• chat_id (int | str, optional) – Required if inline_message_id is not specified.
Unique identifier for the target chat or username of the target channel (in the format
@channelusername).
• message_id (int, optional) – Required if inline_message_id is not specified.
Identifier of the sent message with live location to stop.
Shortcuts
telegram.Message.stop_poll()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• message_id (int) – Identifier of the original message with the poll.
• reply_markup (telegram.InlineKeyboardMarkup, optional) – An object for a
new message inline keyboard.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message to be edited was sent
Added in version 21.4.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
property supports_inline_queries
Bot’s telegram.User.supports_inline_queries attribute. Shortcut for the corresponding at-
tribute of bot.
Type
bool
to_dict(recursive=True)
See telegram.TelegramObject.to_dict().
property token
Bot’s unique authentication token.
Added in version 20.0.
Type
str
async unbanChatMember(chat_id, user_id, only_if_banned=None, *, read_timeout=None,
write_timeout=None, connect_timeout=None, pool_timeout=None,
api_kwargs=None)
Alias for unban_chat_member()
async unbanChatSenderChat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None,
connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for unban_chat_sender_chat()
async unban_chat_member(chat_id, user_id, only_if_banned=None, *, read_timeout=None,
write_timeout=None, connect_timeout=None, pool_timeout=None,
api_kwargs=None)
Use this method to unban a previously kicked user in a supergroup or channel.
The user will not return to the group or channel automatically, but will be able to join via link, etc. The
bot must be an administrator for this to work. By default, this method guarantees that after the call the
user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they
will also be removed from the chat. If you don’t want this, use the parameter only_if_banned.
Shortcuts
• telegram.Chat.unban_member()
• telegram.ChatFullInfo.unban_member()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• user_id (int) – Unique identifier of the target user.
• only_if_banned (bool, optional) – Do nothing if the user is not banned.
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.unban_chat()
• telegram.Chat.unban_sender_chat()
• telegram.ChatFullInfo.unban_chat()
• telegram.ChatFullInfo.unban_sender_chat()
Shortcuts
• telegram.Chat.unhide_general_forum_topic()
• telegram.ChatFullInfo.unhide_general_forum_topic()
Shortcuts
• telegram.Chat.unpin_all_messages()
• telegram.ChatFullInfo.unpin_all_messages()
• telegram.User.unpin_all_messages()
Parameters
chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
Keyword Arguments
• read_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.read_timeout. Defaults to DEFAULT_NONE.
• write_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.write_timeout. Defaults to DEFAULT_NONE.
• connect_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.connect_timeout. Defaults to DEFAULT_NONE.
• pool_timeout (float | None, optional) – Value to pass to telegram.request.
BaseRequest.post.pool_timeout. Defaults to DEFAULT_NONE.
• api_kwargs (dict, optional) – Arbitrary keyword arguments to be passed to the Tele-
gram API. See do_api_request() for limitations.
Returns
On success, True is returned.
Return type
bool
Raises
telegram.error.TelegramError –
Shortcuts
• telegram.Chat.unpin_all_forum_topic_messages()
• telegram.ChatFullInfo.unpin_all_forum_topic_messages()
• telegram.Message.unpin_all_forum_topic_messages()
Shortcuts
• telegram.Chat.unpin_all_general_forum_topic_messages()
• telegram.ChatFullInfo.unpin_all_general_forum_topic_messages()
Shortcuts
• telegram.Chat.unpin_message()
• telegram.ChatFullInfo.unpin_message()
• telegram.Message.unpin()
• telegram.User.unpin_message()
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• message_id (int, optional) – Identifier of the message to unpin. Required if
business_connection_id is specified. If not specified, the most recent pinned mes-
sage (by sending date) will be unpinned.
• business_connection_id (str, optional) – Unique identifier of the business con-
nection on behalf of which the message will be unpinned.
Added in version 21.5.
Keyword Arguments
Shortcuts
• telegram.Chat.verify()
• telegram.ChatFullInfo.verify()
Shortcuts
telegram.User.verify()
Available Types
Animation
Use In
• telegram.Bot.get_file()
• telegram.Bot.send_animation()
Available In
• telegram.ExternalReplyInfo.animation
• telegram.Game.animation
• telegram.InputMediaAnimation.media
• telegram.Message.animation
• telegram.Message.effective_attachment
Changed in version 20.5: Removed the deprecated argument and attribute thumb.
Parameters
• file_id (str) – Identifier for this file, which can be used to download or reuse the file.
• file_unique_id (str) – Unique identifier for this file, which is supposed to be the
same over time and for different bots. Can’t be used to download or reuse the file.
• width (int) – Video width as defined by the sender.
• height (int) – Video height as defined by the sender.
• duration (int) – Duration of the video in seconds as defined by the sender.
• file_name (str, optional) – Original animation filename as defined by the sender.
• mime_type (str, optional) – MIME type of the file as defined by the sender.
• file_size (int, optional) – File size in bytes.
• thumbnail (telegram.PhotoSize, optional) – Animation thumbnail as defined by
sender.
Added in version 20.2.
file_id
Identifier for this file, which can be used to download or reuse the file.
Type
str
file_unique_id
Unique identifier for this file, which is supposed to be the same over time and for different bots. Can’t
be used to download or reuse the file.
Type
str
width
Video width as defined by the sender.
Type
int
height
Video height as defined by the sender.
Type
int
duration
Duration of the video in seconds as defined by the sender.
Type
int
file_name
Optional. Original animation filename as defined by the sender.
Type
str
mime_type
Optional. MIME type of the file as defined by the sender.
Type
str
file_size
Optional. File size in bytes.
Type
int
thumbnail
Optional. Animation thumbnail as defined by sender.
Added in version 20.2.
Type
telegram.PhotoSize
__dir__()
Default dir() implementation.
__format__(format_spec, / (Positional-only parameter separator (PEP 570)))
Default object formatter.
Return str(self) if format_spec is empty. Raise TypeError otherwise.
__ge__(value, / )
Return self>=value.
__getattribute__(name, / )
Return getattr(self, name).
__gt__(value, / )
Return self>value.
classmethod __init_subclass__()
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
__le__(value, / )
Return self<=value.
__lt__(value, / )
Return self<value.
__ne__(value, / )
Return self!=value.
classmethod __new__(*args, **kwargs)
__reduce__()
Helper for pickle.
__reduce_ex__(protocol, / )
Helper for pickle.
__sizeof__()
Size of object in memory, in bytes.
__str__()
Return str(self).
classmethod __subclasshook__(object, / )
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotIm-
plemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the
normal algorithm (and the outcome is cached).
classmethod de_json(data, bot=None)
See telegram.TelegramObject.de_json().
async get_file(*, read_timeout=None, write_timeout=None, connect_timeout=None,
pool_timeout=None, api_kwargs=None)
Convenience wrapper over telegram.Bot.get_file()
For the documentation of the arguments, please see telegram.Bot.get_file().
Returns
telegram.File
Raises
telegram.error.TelegramError –
Audio
Use In
• telegram.Bot.get_file()
• telegram.Bot.send_audio()
Available In
• telegram.ExternalReplyInfo.audio
• telegram.InputMediaAudio.media
• telegram.Message.audio
• telegram.Message.effective_attachment
Changed in version 20.5: Removed the deprecated argument and attribute thumb.
Parameters
• file_id (str) – Identifier for this file, which can be used to download or reuse the file.
• file_unique_id (str) – Unique identifier for this file, which is supposed to be the
same over time and for different bots. Can’t be used to download or reuse the file.
• duration (int) – Duration of the audio in seconds as defined by the sender.
• performer (str, optional) – Performer of the audio as defined by the sender or by audio
tags.
• title (str, optional) – Title of the audio as defined by the sender or by audio tags.
• file_name (str, optional) – Original filename as defined by the sender.
• mime_type (str, optional) – MIME type of the file as defined by the sender.
• file_size (int, optional) – File size in bytes.
• thumbnail (telegram.PhotoSize, optional) – Thumbnail of the album cover to
which the music file belongs.
Added in version 20.2.
file_id
Identifier for this file, which can be used to download or reuse the file.
Type
str
file_unique_id
Unique identifier for this file, which is supposed to be the same over time and for different bots. Can’t
be used to download or reuse the file.
Type
str
duration
Duration of the audio in seconds as defined by the sender.
Type
int
performer
Optional. Performer of the audio as defined by the sender or by audio tags.
Type
str
title
Optional. Title of the audio as defined by the sender or by audio tags.
Type
str
file_name
Optional. Original filename as defined by the sender.
Type
str
mime_type
Optional. MIME type of the file as defined by the sender.
Type
str
file_size
Optional. File size in bytes.
Type
int
thumbnail
Optional. Thumbnail of the album cover to which the music file belongs.
Added in version 20.2.
Type
telegram.PhotoSize
__dir__()
Default dir() implementation.
__format__(format_spec, / )
Default object formatter.
Return str(self) if format_spec is empty. Raise TypeError otherwise.
__ge__(value, / )
Return self>=value.
__getattribute__(name, / )
Return getattr(self, name).
__gt__(value, / )
Return self>value.
classmethod __init_subclass__()
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
__le__(value, / )
Return self<=value.
__lt__(value, / )
Return self<value.
__ne__(value, / )
Return self!=value.
classmethod __new__(*args, **kwargs)
__reduce__()
Helper for pickle.
__reduce_ex__(protocol, / )
Helper for pickle.
__sizeof__()
Size of object in memory, in bytes.
__str__()
Return str(self).
classmethod __subclasshook__(object, / )
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotIm-
plemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the
normal algorithm (and the outcome is cached).
classmethod de_json(data, bot=None)
See telegram.TelegramObject.de_json().
async get_file(*, read_timeout=None, write_timeout=None, connect_timeout=None,
pool_timeout=None, api_kwargs=None)
Convenience wrapper over telegram.Bot.get_file()
For the documentation of the arguments, please see telegram.Bot.get_file().
Returns
telegram.File
Raises
telegram.error.TelegramError –
Birthdate
Available In
telegram.ChatFullInfo.birthdate
year
Optional. Year of the user’s birth.
Type
int
to_date(year=None)
Return the birthdate as a date object.
Changed in version 21.2: Now returns a datetime.date object instead of a datetime.datetime
object, as was originally intended.
Parameters
year (int, optional) – The year to use. Required, if the year was not present.
Returns
The birthdate as a date object.
Return type
datetime.date
BotCommand
Use In
telegram.Bot.set_my_commands()
Returned In
telegram.Bot.get_my_commands()
Parameters
• command (str) – Text of the command; 1- 32 characters. Can contain only lowercase
English letters, digits and underscores.
• description (str) – Description of the command; 1- 256 characters.
command
Text of the command; 1- 32 characters. Can contain only lowercase English letters, digits and under-
scores.
Type
str
description
Description of the command; 1- 256 characters.
Type
str
MAX_COMMAND = 32
telegram.constants.BotCommandLimit.MAX_COMMAND
Added in version 20.0.
MAX_DESCRIPTION = 256
telegram.constants.BotCommandLimit.MAX_DESCRIPTION
Added in version 20.0.
MIN_COMMAND = 1
telegram.constants.BotCommandLimit.MIN_COMMAND
Added in version 20.0.
MIN_DESCRIPTION = 1
telegram.constants.BotCommandLimit.MIN_DESCRIPTION
Added in version 20.0.
BotCommandScope
Note
Please see the official docs on how Telegram determines which commands to display.
Use In
• telegram.Bot.delete_my_commands()
• telegram.Bot.get_my_commands()
• telegram.Bot.set_my_commands()
type
Scope type.
Type
str
ALL_CHAT_ADMINISTRATORS = 'all_chat_administrators'
telegram.constants.BotCommandScopeType.ALL_CHAT_ADMINISTRATORS
ALL_GROUP_CHATS = 'all_group_chats'
telegram.constants.BotCommandScopeType.ALL_GROUP_CHATS
ALL_PRIVATE_CHATS = 'all_private_chats'
telegram.constants.BotCommandScopeType.ALL_PRIVATE_CHATS
CHAT = 'chat'
telegram.constants.BotCommandScopeType.CHAT
CHAT_ADMINISTRATORS = 'chat_administrators'
telegram.constants.BotCommandScopeType.CHAT_ADMINISTRATORS
CHAT_MEMBER = 'chat_member'
telegram.constants.BotCommandScopeType.CHAT_MEMBER
DEFAULT = 'default'
telegram.constants.BotCommandScopeType.DEFAULT
classmethod de_json(data, bot=None)
Converts JSON data to the appropriate BotCommandScope object, i.e. takes care of selecting the cor-
rect subclass.
Parameters
• data (dict[str, . . . ]) – The JSON data.
• bot (telegram.Bot, optional) – The bot associated with this object. Defaults to
None, in which case shortcut methods will not be available.
Changed in version 21.4: bot is now optional and defaults to None
Returns
The Telegram object.
BotCommandScopeAllChatAdministrators
Use In
• telegram.Bot.delete_my_commands()
• telegram.Bot.get_my_commands()
• telegram.Bot.set_my_commands()
Type
str
BotCommandScopeAllGroupChats
Use In
• telegram.Bot.delete_my_commands()
• telegram.Bot.get_my_commands()
• telegram.Bot.set_my_commands()
BotCommandScopeAllPrivateChats
Use In
• telegram.Bot.delete_my_commands()
• telegram.Bot.get_my_commands()
• telegram.Bot.set_my_commands()
BotCommandScopeChat
Use In
• telegram.Bot.delete_my_commands()
• telegram.Bot.get_my_commands()
• telegram.Bot.set_my_commands()
BotCommandScopeChatAdministrators
Use In
• telegram.Bot.delete_my_commands()
• telegram.Bot.get_my_commands()
• telegram.Bot.set_my_commands()
Type
str | int
BotCommandScopeChatMember
Use In
• telegram.Bot.delete_my_commands()
• telegram.Bot.get_my_commands()
• telegram.Bot.set_my_commands()
BotCommandScopeDefault
Use In
• telegram.Bot.delete_my_commands()
• telegram.Bot.get_my_commands()