TeleBot version#
TeleBot methods#
- class telebot.ExceptionHandler#
Bases:
object
Class for handling exceptions while Polling
- handle(exception)#
- class telebot.Handler(callback, *args, **kwargs)#
Bases:
object
Class for (next step|reply) handlers
- telebot.REPLY_MARKUP_TYPES#
telebot
- Type
Module
alias of
Union
[telebot.types.InlineKeyboardMarkup
,telebot.types.ReplyKeyboardMarkup
,telebot.types.ReplyKeyboardRemove
,telebot.types.ForceReply
]
- class telebot.TeleBot(token, parse_mode=None, threaded=True, skip_pending=False, num_threads=2, next_step_backend=None, reply_backend=None, exception_handler=None, last_update_id=0, suppress_middleware_excepions=False, state_storage=<telebot.storage.memory_storage.StateMemoryStorage object>, use_class_middlewares=False)#
Bases:
object
This is the main synchronous class for Bot.
It allows you to add handlers for different kind of updates.
Usage:
from telebot import TeleBot bot = TeleBot('token') # get token from @BotFather
See more examples in examples/ directory: https://github.com/eternnoir/pyTelegramBotAPI/tree/master/examples
- add_callback_query_handler(handler_dict)#
Adds a callback request handler Note that you should use register_callback_query_handler to add callback_query_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_channel_post_handler(handler_dict)#
Adds channel post handler Note that you should use register_channel_post_handler to add channel_post_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_chat_join_request_handler(handler_dict)#
Adds a chat_join_request handler. Note that you should use register_chat_join_request_handler to add chat_join_request_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_chat_member_handler(handler_dict)#
Adds a chat_member handler. Note that you should use register_chat_member_handler to add chat_member_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_chosen_inline_handler(handler_dict)#
Description: TBD Note that you should use register_chosen_inline_handler to add chosen_inline_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_custom_filter(custom_filter: Union[telebot.custom_filters.SimpleCustomFilter, telebot.custom_filters.AdvancedCustomFilter])#
Create custom filter.
- Parameters
custom_filter – Class with check(message) method.
custom_filter – Custom filter class with key.
- add_data(user_id: int, chat_id: Optional[int] = None, **kwargs)#
Add data to states.
- Parameters
user_id –
chat_id –
- add_edited_channel_post_handler(handler_dict)#
Adds the edit channel post handler Note that you should use register_edited_channel_post_handler to add edited_channel_post_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_edited_message_handler(handler_dict)#
Adds the edit message handler Note that you should use register_edited_message_handler to add edited_message_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_inline_handler(handler_dict)#
Adds inline call handler Note that you should use register_inline_handler to add inline_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_message_handler(handler_dict)#
Adds a message handler Note that you should use register_message_handler to add message_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_middleware_handler(handler, update_types=None)#
Add middleware handler.
- Parameters
handler –
update_types –
- Returns
- add_my_chat_member_handler(handler_dict)#
Adds a my_chat_member handler. Note that you should use register_my_chat_member_handler to add my_chat_member_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_poll_answer_handler(handler_dict)#
Adds a poll_answer request handler. Note that you should use register_poll_answer_handler to add poll_answer_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_poll_handler(handler_dict)#
Adds a poll request handler Note that you should use register_poll_handler to add poll_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_pre_checkout_query_handler(handler_dict)#
Adds a pre-checkout request handler Note that you should use register_pre_checkout_query_handler to add pre_checkout_query_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_shipping_query_handler(handler_dict)#
Adds a shipping request handler. Note that you should use register_shipping_query_handler to add shipping_query_handler to the bot.
- Parameters
handler_dict –
- Returns
- add_sticker_to_set(user_id: int, name: str, emojis: str, png_sticker: Optional[Union[Any, str]] = None, tgs_sticker: Optional[Union[Any, str]] = None, webm_sticker: Optional[Union[Any, str]] = None, mask_position: Optional[telebot.types.MaskPosition] = None) bool #
Use this method to add a new sticker to a set created by the bot. It’s required to pass png_sticker or tgs_sticker. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#addstickertoset
- Parameters
user_id –
name –
emojis –
png_sticker – Required if tgs_sticker is None
tgs_sticker – Required if png_sticker is None
webm_sticker –
mask_position –
- Returns
- answer_callback_query(callback_query_id: int, text: Optional[str] = None, show_alert: Optional[bool] = None, url: Optional[str] = None, cache_time: Optional[int] = None) bool #
Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
Telegram documentation: https://core.telegram.org/bots/api#answercallbackquery
- Parameters
callback_query_id –
text –
show_alert –
url –
cache_time –
- Returns
- answer_inline_query(inline_query_id: str, results: List[Any], cache_time: Optional[int] = None, is_personal: Optional[bool] = None, next_offset: Optional[str] = None, switch_pm_text: Optional[str] = None, switch_pm_parameter: Optional[str] = None) bool #
Use this method to send answers to an inline query. On success, True is returned. No more than 50 results per query are allowed.
Telegram documentation: https://core.telegram.org/bots/api#answerinlinequery
- Parameters
inline_query_id – Unique identifier for the answered query
results – Array of results for the inline query
cache_time – The maximum amount of time in seconds that the result of the inline query may be cached on the server.
is_personal – Pass True, if results may be cached on the server side only for the user that sent the query.
next_offset – Pass the offset that a client should send in the next query with the same text to receive more results.
switch_pm_parameter – If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter
switch_pm_text – Parameter for the start message sent to the bot when user presses the switch button
- Returns
True means success.
- answer_pre_checkout_query(pre_checkout_query_id: int, ok: bool, error_message: Optional[str] = None) bool #
Response to a request for pre-inspection.
Telegram documentation: https://core.telegram.org/bots/api#answerprecheckoutquery
- Parameters
pre_checkout_query_id –
ok –
error_message –
- Returns
- answer_shipping_query(shipping_query_id: str, ok: bool, shipping_options: Optional[List[telebot.types.ShippingOption]] = None, error_message: Optional[str] = None) bool #
Asks for an answer to a shipping question.
Telegram documentation: https://core.telegram.org/bots/api#answershippingquery
- Parameters
shipping_query_id –
ok –
shipping_options –
error_message –
- Returns
- approve_chat_join_request(chat_id: Union[str, int], user_id: Union[int, str]) bool #
Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#approvechatjoinrequest
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
user_id – Unique identifier of the target user
- Returns
True on success.
- ban_chat_member(chat_id: Union[int, str], user_id: int, until_date: Optional[Union[int, datetime.datetime]] = None, revoke_messages: Optional[bool] = None) bool #
Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#banchatmember
- Parameters
chat_id – Int or string : Unique identifier for the target group or username of the target supergroup
user_id – Int : Unique identifier of the target user
until_date – Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
revoke_messages – Bool: Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.
- Returns
boolean
- ban_chat_sender_chat(chat_id: Union[int, str], sender_chat_id: Union[int, str]) bool #
Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#banchatsenderchat
- Parameters
chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
sender_chat_id – Unique identifier of the target sender chat
- Returns
True on success.
- callback_query_handler(func, **kwargs)#
Callback request handler decorator
- Parameters
func –
kwargs –
- Returns
- channel_post_handler(commands=None, regexp=None, func=None, content_types=None, **kwargs)#
Channel post handler decorator
- Parameters
commands –
regexp –
func –
content_types –
kwargs –
- Returns
- chat_join_request_handler(func=None, **kwargs)#
chat_join_request handler
- Parameters
func –
kwargs –
- Returns
- chat_member_handler(func=None, **kwargs)#
chat_member handler.
- Parameters
func –
kwargs –
- Returns
- static check_commands_input(commands, method_name)#
- static check_regexp_input(regexp, method_name)#
- chosen_inline_handler(func, **kwargs)#
Description: TBD
- Parameters
func –
kwargs –
- Returns
- clear_reply_handlers(message: telebot.types.Message) None #
Clears all callback functions registered by register_for_reply() and register_for_reply_by_message_id().
- Parameters
message – The message for which we want to clear reply handlers
- clear_reply_handlers_by_message_id(message_id: int) None #
Clears all callback functions registered by register_for_reply() and register_for_reply_by_message_id().
- Parameters
message_id – The message id for which we want to clear reply handlers
- clear_step_handler(message: telebot.types.Message) None #
Clears all callback functions registered by register_next_step_handler().
- Parameters
message – The message for which we want to handle new message after that in same chat.
- clear_step_handler_by_chat_id(chat_id: Union[int, str]) None #
Clears all callback functions registered by register_next_step_handler().
- Parameters
chat_id – The chat for which we want to clear next step handlers
- close() bool #
Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn’t launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#close
- copy_message(chat_id: Union[int, str], from_chat_id: Union[int, str], message_id: int, caption: Optional[str] = None, parse_mode: Optional[str] = None, caption_entities: Optional[List[telebot.types.MessageEntity]] = None, disable_notification: Optional[bool] = None, protect_content: Optional[bool] = None, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None) int #
Use this method to copy messages of any kind.
Telegram documentation: https://core.telegram.org/bots/api#copymessage
- Parameters
chat_id – which chat to forward
from_chat_id – which chat message from
message_id – message id
caption –
parse_mode –
caption_entities –
disable_notification –
protect_content –
reply_to_message_id –
allow_sending_without_reply –
reply_markup –
timeout –
- Returns
API reply.
- create_chat_invite_link(chat_id: Union[int, str], name: Optional[str] = None, expire_date: Optional[Union[int, datetime.datetime]] = None, member_limit: Optional[int] = None, creates_join_request: Optional[bool] = None) telebot.types.ChatInviteLink #
Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Telegram documentation: https://core.telegram.org/bots/api#createchatinvitelink
- Parameters
chat_id – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
name – Invite link name; 0-32 characters
expire_date – Point in time (Unix timestamp) when the link will expire
member_limit – Maximum number of users that can be members of the chat simultaneously
creates_join_request – True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified
- Returns
- create_new_sticker_set(user_id: int, name: str, title: str, emojis: str, png_sticker: Optional[Union[Any, str]] = None, tgs_sticker: Optional[Union[Any, str]] = None, webm_sticker: Optional[Union[Any, str]] = None, contains_masks: Optional[bool] = None, mask_position: Optional[telebot.types.MaskPosition] = None) bool #
Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset
- Parameters
user_id –
name –
title –
emojis –
png_sticker –
tgs_sticker –
webm_sticker –
contains_masks –
mask_position –
- Returns
- decline_chat_join_request(chat_id: Union[str, int], user_id: Union[int, str]) bool #
Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#declinechatjoinrequest
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
user_id – Unique identifier of the target user
- Returns
True on success.
- delete_chat_photo(chat_id: Union[int, str]) bool #
Use this method to delete a chat photo. Photos can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#deletechatphoto
- Parameters
chat_id – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
- delete_chat_sticker_set(chat_id: Union[int, str]) bool #
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#deletechatstickerset
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
- Returns
API reply.
- delete_message(chat_id: Union[int, str], message_id: int, timeout: Optional[int] = None) bool #
Use this method to delete message. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#deletemessage
- Parameters
chat_id – in which chat to delete
message_id – which message to delete
timeout –
- Returns
API reply.
- delete_my_commands(scope: Optional[telebot.types.BotCommandScope] = None, language_code: Optional[str] = None) bool #
Use this method to delete the list of the bot’s commands for the given scope and user language. After deletion, higher level commands will be shown to affected users. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#deletemycommands
- Parameters
scope – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
language_code – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
- delete_state(user_id: int, chat_id: Optional[int] = None) None #
Delete the current state of a user.
- Parameters
user_id –
chat_id –
- Returns
- delete_sticker_from_set(sticker: str) bool #
Use this method to delete a sticker from a set created by the bot. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#deletestickerfromset
- Parameters
sticker –
- Returns
- delete_webhook(drop_pending_updates=None, timeout=None)#
Use this method to remove webhook integration if you decide to switch back to getUpdates.
Telegram documentation: https://core.telegram.org/bots/api#deletewebhook
- Parameters
drop_pending_updates – Pass True to drop all pending updates
timeout – Integer. Request connection timeout
- Returns
bool
- disable_save_next_step_handlers()#
Disable saving next step handlers (by default saving disable)
This function is left to keep backward compatibility whose purpose was to disable file saving capability for handlers. For the same purpose, MemoryHandlerBackend is reassigned as a new next_step_backend backend instead of FileHandlerBackend.
Most probably this function should be deprecated in future major releases
- disable_save_reply_handlers()#
Disable saving next step handlers (by default saving disable)
This function is left to keep backward compatibility whose purpose was to disable file saving capability for handlers. For the same purpose, MemoryHandlerBackend is reassigned as a new reply_backend backend instead of FileHandlerBackend.
Most probably this function should be deprecated in future major releases
- download_file(file_path: str) bytes #
- edit_chat_invite_link(chat_id: Union[int, str], invite_link: Optional[str] = None, name: Optional[str] = None, expire_date: Optional[Union[int, datetime.datetime]] = None, member_limit: Optional[int] = None, creates_join_request: Optional[bool] = None) telebot.types.ChatInviteLink #
Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Telegram documentation: https://core.telegram.org/bots/api#editchatinvitelink
- Parameters
chat_id – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
name – Invite link name; 0-32 characters
invite_link – The invite link to edit
expire_date – Point in time (Unix timestamp) when the link will expire
member_limit – Maximum number of users that can be members of the chat simultaneously
creates_join_request – True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified
- Returns
Use this method to edit captions of messages.
Telegram documentation: https://core.telegram.org/bots/api#editmessagecaption
- Parameters
caption –
chat_id –
message_id –
inline_message_id –
parse_mode –
caption_entities –
reply_markup –
- Returns
- edit_message_live_location(latitude: float, longitude: float, chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None, horizontal_accuracy: Optional[float] = None, heading: Optional[int] = None, proximity_alert_radius: Optional[int] = None) telebot.types.Message #
Use this method to edit live location.
Telegram documentation: https://core.telegram.org/bots/api#editmessagelivelocation
- Parameters
latitude –
longitude –
chat_id –
message_id –
reply_markup –
timeout –
inline_message_id –
horizontal_accuracy –
heading –
proximity_alert_radius –
- Returns
- edit_message_media(media: Any, chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None) Union[telebot.types.Message, bool] #
Use this method to edit animation, audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can’t be uploaded. Use previously uploaded file via its file_id or specify a URL.
Telegram documentation: https://core.telegram.org/bots/api#editmessagemedia
- Parameters
media –
chat_id –
message_id –
inline_message_id –
reply_markup –
- Returns
- edit_message_reply_markup(chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None) Union[telebot.types.Message, bool] #
Use this method to edit only the reply markup of messages.
Telegram documentation: https://core.telegram.org/bots/api#editmessagereplymarkup
- Parameters
chat_id –
message_id –
inline_message_id –
reply_markup –
- Returns
- edit_message_text(text: str, chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, parse_mode: Optional[str] = None, entities: Optional[List[telebot.types.MessageEntity]] = None, disable_web_page_preview: Optional[bool] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None) Union[telebot.types.Message, bool] #
Use this method to edit text and game messages.
Telegram documentation: https://core.telegram.org/bots/api#editmessagetext
- Parameters
text –
chat_id –
message_id –
inline_message_id –
parse_mode –
entities –
disable_web_page_preview –
reply_markup –
- Returns
- edited_channel_post_handler(commands=None, regexp=None, func=None, content_types=None, **kwargs)#
Edit channel post handler decorator
- Parameters
commands –
regexp –
func –
content_types –
kwargs –
- Returns
- edited_message_handler(commands=None, regexp=None, func=None, content_types=None, chat_types=None, **kwargs)#
Edit message handler decorator
- Parameters
commands –
regexp –
func –
content_types –
chat_types – list of chat types
kwargs –
- Returns
- enable_save_next_step_handlers(delay=120, filename='./.handler-saves/step.save')#
Enable saving next step handlers (by default saving disabled)
This function explicitly assigns FileHandlerBackend (instead of Saver) just to keep backward compatibility whose purpose was to enable file saving capability for handlers. And the same implementation is now available with FileHandlerBackend
Most probably this function should be deprecated in future major releases
- Parameters
delay – Delay between changes in handlers and saving
filename – Filename of save file
- enable_save_reply_handlers(delay=120, filename='./.handler-saves/reply.save')#
Enable saving reply handlers (by default saving disable)
This function explicitly assigns FileHandlerBackend (instead of Saver) just to keep backward compatibility whose purpose was to enable file saving capability for handlers. And the same implementation is now available with FileHandlerBackend
Most probably this function should be deprecated in future major releases
- Parameters
delay – Delay between changes in handlers and saving
filename – Filename of save file
- enable_saving_states(filename='./.state-save/states.pkl')#
Enable saving states (by default saving disabled)
- Parameters
filename – Filename of saving file
- export_chat_invite_link(chat_id: Union[int, str]) str #
Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Telegram documentation: https://core.telegram.org/bots/api#exportchatinvitelink
- Parameters
chat_id – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
- Returns
exported invite link as String on success.
- forward_message(chat_id: Union[int, str], from_chat_id: Union[int, str], message_id: int, disable_notification: Optional[bool] = None, protect_content: Optional[bool] = None, timeout: Optional[int] = None) telebot.types.Message #
Use this method to forward messages of any kind.
Telegram documentation: https://core.telegram.org/bots/api#forwardmessage
- Parameters
disable_notification –
chat_id – which chat to forward
from_chat_id – which chat message from
message_id – message id
protect_content – Protects the contents of the forwarded message from forwarding and saving
timeout –
- Returns
API reply.
- get_chat(chat_id: Union[int, str]) telebot.types.Chat #
Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
Telegram documentation: https://core.telegram.org/bots/api#getchat
- Parameters
chat_id –
- Returns
API reply.
- get_chat_administrators(chat_id: Union[int, str]) List[telebot.types.ChatMember] #
Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots.
Telegram documentation: https://core.telegram.org/bots/api#getchatadministrators
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
- Returns
API reply.
- get_chat_member(chat_id: Union[int, str], user_id: int) telebot.types.ChatMember #
Use this method to get information about a member of a chat. Returns a ChatMember object on success.
Telegram documentation: https://core.telegram.org/bots/api#getchatmember
- Parameters
chat_id –
user_id –
- Returns
API reply.
- get_chat_member_count(chat_id: Union[int, str]) int #
Use this method to get the number of members in a chat. Returns Int on success.
Telegram documentation: https://core.telegram.org/bots/api#getchatmembercount
- Parameters
chat_id –
- Returns
API reply.
- get_chat_members_count(chat_id: Union[int, str]) int #
This function is deprecated. Use get_chat_member_count instead
- get_file(file_id: str) telebot.types.File #
Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling get_file again.
Telegram documentation: https://core.telegram.org/bots/api#getfile
- Parameters
file_id – File identifier
- get_file_url(file_id: str) str #
Get a valid URL for downloading a file.
- Parameters
file_id – File identifier to get download URL for.
- get_game_high_scores(user_id: int, chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None) List[telebot.types.GameHighScore] #
Gets top points and game play.
Telegram documentation: https://core.telegram.org/bots/api#getgamehighscores
- Parameters
user_id –
chat_id –
message_id –
inline_message_id –
- Returns
- get_me() telebot.types.User #
Returns basic information about the bot in form of a User object.
Telegram documentation: https://core.telegram.org/bots/api#getme
- get_my_commands(scope: Optional[telebot.types.BotCommandScope] = None, language_code: Optional[str] = None) List[telebot.types.BotCommand] #
Use this method to get the current list of the bot’s commands. Returns List of BotCommand on success.
Telegram documentation: https://core.telegram.org/bots/api#getmycommands
- Parameters
scope – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
language_code – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
- get_state(user_id: int, chat_id: Optional[int] = None) Optional[Union[int, str]] #
Get current state of a user.
- Parameters
user_id –
chat_id –
- Returns
state of a user
- get_sticker_set(name: str) telebot.types.StickerSet #
Use this method to get a sticker set. On success, a StickerSet object is returned.
Telegram documentation: https://core.telegram.org/bots/api#getstickerset
- Parameters
name –
- Returns
- get_updates(offset: Optional[int] = None, limit: Optional[int] = None, timeout: Optional[int] = 20, allowed_updates: Optional[List[str]] = None, long_polling_timeout: int = 20) List[telebot.types.Update] #
Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.
Telegram documentation: https://core.telegram.org/bots/api#getupdates
- Parameters
allowed_updates – Array of string. List the types of updates you want your bot to receive.
offset – Integer. Identifier of the first update to be returned.
limit – Integer. Limits the number of updates to be retrieved.
timeout – Integer. Request connection timeout
long_polling_timeout – Timeout in seconds for long polling.
- Returns
array of Updates
- get_user_profile_photos(user_id: int, offset: Optional[int] = None, limit: Optional[int] = None) telebot.types.UserProfilePhotos #
Retrieves the user profile photos of the person with ‘user_id’
Telegram documentation: https://core.telegram.org/bots/api#getuserprofilephotos
- Parameters
user_id – Integer - Unique identifier of the target user
offset –
limit –
- Returns
API reply.
- get_webhook_info(timeout: Optional[int] = None)#
Use this method to get current webhook status. Requires no parameters. If the bot is using getUpdates, will return an object with the url field empty.
Telegram documentation: https://core.telegram.org/bots/api#getwebhookinfo
- Parameters
timeout – Integer. Request connection timeout
- Returns
On success, returns a WebhookInfo object.
- infinity_polling(timeout: int = 20, skip_pending: bool = False, long_polling_timeout: int = 20, logger_level=40, allowed_updates: Optional[List[str]] = None, *args, **kwargs)#
Wrap polling with infinite loop and exception handling to avoid bot stops polling.
- Parameters
timeout – Request connection timeout
long_polling_timeout – Timeout in seconds for long polling (see API docs)
skip_pending – skip old updates
logger_level – Custom logging level for infinity_polling logging. Use logger levels from logging as a value. None/NOTSET = no error logging
allowed_updates –
A list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See util.update_types for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used.
Please note that this parameter doesn’t affect updates created before the call to the get_updates, so unwanted updates may be received for a short period of time.
- inline_handler(func, **kwargs)#
Inline call handler decorator
- Parameters
func –
kwargs –
- Returns
- kick_chat_member(chat_id: Union[int, str], user_id: int, until_date: Optional[Union[int, datetime.datetime]] = None, revoke_messages: Optional[bool] = None) bool #
This function is deprecated. Use ban_chat_member instead
- leave_chat(chat_id: Union[int, str]) bool #
Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#leavechat
- Parameters
chat_id –
- Returns
API reply.
- load_next_step_handlers(filename='./.handler-saves/step.save', del_file_after_loading=True)#
Load next step handlers from save file
This function is left to keep backward compatibility whose purpose was to load handlers from file with the help of FileHandlerBackend and is only recommended to use if next_step_backend was assigned as FileHandlerBackend before entering this function
Most probably this function should be deprecated in future major releases
- Parameters
filename – Filename of the file where handlers was saved
del_file_after_loading – Is passed True, after loading save file will be deleted
- load_reply_handlers(filename='./.handler-saves/reply.save', del_file_after_loading=True)#
Load reply handlers from save file
This function is left to keep backward compatibility whose purpose was to load handlers from file with the help of FileHandlerBackend and is only recommended to use if reply_backend was assigned as FileHandlerBackend before entering this function
Most probably this function should be deprecated in future major releases
- Parameters
filename – Filename of the file where handlers was saved
del_file_after_loading – Is passed True, after loading save file will be deleted
- log_out() bool #
Use this method to log out from the cloud Bot API server before launching the bot locally. You MUST log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#logout
- message_handler(commands=None, regexp=None, func=None, content_types=None, chat_types=None, **kwargs)#
Message handler decorator. This decorator can be used to decorate functions that must handle certain types of messages. All message handlers are tested in the order they were added.
Example:
bot = TeleBot('TOKEN') # Handles all messages which text matches regexp. @bot.message_handler(regexp='someregexp') def command_help(message): bot.send_message(message.chat.id, 'Did someone call for help?') # Handles messages in private chat @bot.message_handler(chat_types=['private']) # You can add more chat types def command_help(message): bot.send_message(message.chat.id, 'Private chat detected, sir!') # Handle all sent documents of type 'text/plain'. @bot.message_handler(func=lambda message: message.document.mime_type == 'text/plain', content_types=['document']) def command_handle_document(message): bot.send_message(message.chat.id, 'Document received, sir!') # Handle all other messages. @bot.message_handler(func=lambda message: True, content_types=['audio', 'photo', 'voice', 'video', 'document', 'text', 'location', 'contact', 'sticker']) def default_command(message): bot.send_message(message.chat.id, "This is the default command handler.")
- Parameters
commands – Optional list of strings (commands to handle).
regexp – Optional regular expression.
func – Optional lambda function. The lambda receives the message to test as the first parameter. It must return True if the command should handle the message.
content_types – Supported message content types. Must be a list. Defaults to [‘text’].
chat_types – list of chat types
- middleware_handler(update_types=None)#
Middleware handler decorator.
This decorator can be used to decorate functions that must be handled as middlewares before entering any other message handlers But, be careful and check type of the update inside the handler if more than one update_type is given
Example:
bot = TeleBot('TOKEN') # Print post message text before entering to any post_channel handlers @bot.middleware_handler(update_types=['channel_post', 'edited_channel_post']) def print_channel_post_text(bot_instance, channel_post): print(channel_post.text) # Print update id before entering to any handlers @bot.middleware_handler() def print_channel_post_text(bot_instance, update): print(update.update_id)
- Parameters
update_types – Optional list of update types that can be passed into the middleware handler.
- my_chat_member_handler(func=None, **kwargs)#
my_chat_member handler.
- Parameters
func –
kwargs –
- Returns
- pin_chat_message(chat_id: Union[int, str], message_id: int, disable_notification: Optional[bool] = False) bool #
Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#pinchatmessage
- Parameters
chat_id – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
message_id – Int: Identifier of a message to pin
disable_notification – Bool: Pass True, if it is not necessary to send a notification to all group members about the new pinned message
- Returns
- poll_answer_handler(func=None, **kwargs)#
Poll_answer request handler
- Parameters
func –
kwargs –
- Returns
- poll_handler(func, **kwargs)#
Poll request handler
- Parameters
func –
kwargs –
- Returns
- polling(non_stop: bool = False, skip_pending=False, interval: int = 0, timeout: int = 20, long_polling_timeout: int = 20, allowed_updates: Optional[List[str]] = None, none_stop: Optional[bool] = None)#
This function creates a new Thread that calls an internal __retrieve_updates function. This allows the bot to retrieve Updates automagically and notify listeners and message handlers accordingly.
Warning: Do not call this function more than once!
Always get updates.
- Parameters
interval – Delay between two update retrivals
non_stop – Do not stop polling when an ApiException occurs.
timeout – Request connection timeout
skip_pending – skip old updates
long_polling_timeout – Timeout in seconds for long polling (see API docs)
allowed_updates –
A list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See util.update_types for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used.
Please note that this parameter doesn’t affect updates created before the call to the get_updates, so unwanted updates may be received for a short period of time.
none_stop – Deprecated, use non_stop. Old typo f***up compatibility
- Returns
- pre_checkout_query_handler(func, **kwargs)#
Pre-checkout request handler
- Parameters
func –
kwargs –
- Returns
- process_middlewares(update)#
- process_new_callback_query(new_callback_querys)#
- process_new_channel_posts(channel_post)#
- process_new_chat_join_request(chat_join_request)#
- process_new_chat_member(chat_members)#
- process_new_chosen_inline_query(new_chosen_inline_querys)#
- process_new_edited_channel_posts(edited_channel_post)#
- process_new_edited_messages(edited_message)#
- process_new_inline_query(new_inline_querys)#
- process_new_messages(new_messages)#
- process_new_my_chat_member(my_chat_members)#
- process_new_poll(polls)#
- process_new_poll_answer(poll_answers)#
- process_new_pre_checkout_query(pre_checkout_querys)#
- process_new_shipping_query(new_shipping_querys)#
- process_new_updates(updates)#
Processes new updates. Just pass list of subclasses of Update to this method.
- Parameters
updates – List of Update objects
- promote_chat_member(chat_id: Union[int, str], user_id: int, can_change_info: Optional[bool] = None, can_post_messages: Optional[bool] = None, can_edit_messages: Optional[bool] = None, can_delete_messages: Optional[bool] = None, can_invite_users: Optional[bool] = None, can_restrict_members: Optional[bool] = None, can_pin_messages: Optional[bool] = None, can_promote_members: Optional[bool] = None, is_anonymous: Optional[bool] = None, can_manage_chat: Optional[bool] = None, can_manage_voice_chats: Optional[bool] = None) bool #
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user.
Telegram documentation: https://core.telegram.org/bots/api#promotechatmember
- Parameters
chat_id – 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
can_change_info – Bool: Pass True, if the administrator can change chat title, photo and other settings
can_post_messages – Bool : Pass True, if the administrator can create channel posts, channels only
can_edit_messages – Bool : Pass True, if the administrator can edit messages of other users, channels only
can_delete_messages – Bool : Pass True, if the administrator can delete messages of other users
can_invite_users – Bool : Pass True, if the administrator can invite new users to the chat
can_restrict_members – Bool: Pass True, if the administrator can restrict, ban or unban chat members
can_pin_messages – Bool: Pass True, if the administrator can pin messages, supergroups only
can_promote_members – Bool: Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)
is_anonymous – Bool: Pass True, if the administrator’s presence in the chat is hidden
can_manage_chat – Bool: Pass True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege
can_manage_voice_chats – Bool: Pass True, if the administrator can manage voice chats For now, bots can use this privilege only for passing to other administrators.
- Returns
True on success.
- register_callback_query_handler(callback, func, pass_bot=False, **kwargs)#
Registers callback query handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_channel_post_handler(callback, content_types=None, commands=None, regexp=None, func=None, pass_bot=False, **kwargs)#
Registers channel post message handler.
- Parameters
callback – function to be called
content_types – list of content_types
commands – list of commands
regexp –
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_chat_join_request_handler(callback, func=None, pass_bot=False, **kwargs)#
Registers chat join request handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_chat_member_handler(callback, func=None, pass_bot=False, **kwargs)#
Registers chat member handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_chosen_inline_handler(callback, func, pass_bot=False, **kwargs)#
Registers chosen inline handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_edited_channel_post_handler(callback, content_types=None, commands=None, regexp=None, func=None, pass_bot=False, **kwargs)#
Registers edited channel post message handler.
- Parameters
callback – function to be called
content_types – list of content_types
commands – list of commands
regexp –
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_edited_message_handler(callback, content_types=None, commands=None, regexp=None, func=None, chat_types=None, pass_bot=False, **kwargs)#
Registers edited message handler.
- Parameters
callback – function to be called
content_types – list of content_types
commands – list of commands
regexp –
func –
chat_types – True for private chat
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_for_reply(message: telebot.types.Message, callback: Callable, *args, **kwargs) None #
Registers a callback function to be notified when a reply to message arrives.
Warning: In case callback as lambda function, saving reply handlers will not work.
- Parameters
message – The message for which we are awaiting a reply.
callback – The callback function to be called when a reply arrives. Must accept one message parameter, which will contain the replied message.
- register_for_reply_by_message_id(message_id: int, callback: Callable, *args, **kwargs) None #
Registers a callback function to be notified when a reply to message arrives.
Warning: In case callback as lambda function, saving reply handlers will not work.
- Parameters
message_id – The id of the message for which we are awaiting a reply.
callback – The callback function to be called when a reply arrives. Must accept one message parameter, which will contain the replied message.
- register_inline_handler(callback, func, pass_bot=False, **kwargs)#
Registers inline handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_message_handler(callback, content_types=None, commands=None, regexp=None, func=None, chat_types=None, pass_bot=False, **kwargs)#
Registers message handler.
- Parameters
callback – function to be called
content_types – list of content_types
commands – list of commands
regexp –
func –
chat_types – True for private chat
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_middleware_handler(callback, update_types=None)#
Middleware handler decorator.
This function will create a decorator that can be used to decorate functions that must be handled as middlewares before entering any other message handlers But, be careful and check type of the update inside the handler if more than one update_type is given
Example:
bot = TeleBot(‘TOKEN’)
bot.register_middleware_handler(print_channel_post_text, update_types=[‘channel_post’, ‘edited_channel_post’])
- Parameters
callback –
update_types – Optional list of update types that can be passed into the middleware handler.
- register_my_chat_member_handler(callback, func=None, pass_bot=False, **kwargs)#
Registers my chat member handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_next_step_handler(message: telebot.types.Message, callback: Callable, *args, **kwargs) None #
Registers a callback function to be notified when new message arrives after message.
Warning: In case callback as lambda function, saving next step handlers will not work.
- Parameters
message – The message for which we want to handle new message in the same chat.
callback – The callback function which next new message arrives.
args – Args to pass in callback func
kwargs – Args to pass in callback func
- register_next_step_handler_by_chat_id(chat_id: Union[int, str], callback: Callable, *args, **kwargs) None #
Registers a callback function to be notified when new message arrives after message.
Warning: In case callback as lambda function, saving next step handlers will not work.
- Parameters
chat_id – The chat for which we want to handle new message.
callback – The callback function which next new message arrives.
args – Args to pass in callback func
kwargs – Args to pass in callback func
- register_poll_answer_handler(callback, func, pass_bot=False, **kwargs)#
Registers poll answer handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_poll_handler(callback, func, pass_bot=False, **kwargs)#
Registers poll handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_pre_checkout_query_handler(callback, func, pass_bot=False, **kwargs)#
Registers pre-checkout request handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- register_shipping_query_handler(callback, func, pass_bot=False, **kwargs)#
Registers shipping query handler.
- Parameters
callback – function to be called
func –
pass_bot – Pass TeleBot to handler.
- Returns
decorated function
- remove_webhook()#
- reply_to(message: telebot.types.Message, text: str, **kwargs) telebot.types.Message #
Convenience function for send_message(message.chat.id, text, reply_to_message_id=message.message_id, **kwargs)
- Parameters
message –
text –
kwargs –
- Returns
- reset_data(user_id: int, chat_id: Optional[int] = None)#
Reset data for a user in chat.
- Parameters
user_id –
chat_id –
- restrict_chat_member(chat_id: Union[int, str], user_id: int, until_date: Optional[Union[int, datetime.datetime]] = None, can_send_messages: Optional[bool] = None, can_send_media_messages: Optional[bool] = None, can_send_polls: Optional[bool] = None, can_send_other_messages: Optional[bool] = None, can_add_web_page_previews: Optional[bool] = None, can_change_info: Optional[bool] = None, can_invite_users: Optional[bool] = None, can_pin_messages: Optional[bool] = None) bool #
Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user.
Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember
- Parameters
chat_id – Int or String : Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
user_id – Int : Unique identifier of the target user
until_date – 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
can_send_messages – Pass True, if the user can send text messages, contacts, locations and venues
can_send_media_messages – Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
can_send_polls – Pass True, if the user is allowed to send polls, implies can_send_messages
can_send_other_messages – Pass True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
can_add_web_page_previews – Pass True, if the user may add web page previews to their messages, implies can_send_media_messages
can_change_info – Pass True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups
can_invite_users – Pass True, if the user is allowed to invite new users to the chat, implies can_invite_users
can_pin_messages – Pass True, if the user is allowed to pin messages. Ignored in public supergroups
- Returns
True on success
- retrieve_data(user_id: int, chat_id: Optional[int] = None) Optional[Union[int, str]] #
- revoke_chat_invite_link(chat_id: Union[int, str], invite_link: str) telebot.types.ChatInviteLink #
Use this method to revoke an invite link created by the bot. Note: If the primary link is revoked, a new link is automatically generated The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Telegram documentation: https://core.telegram.org/bots/api#revokechatinvitelink
- Parameters
chat_id – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
invite_link – The invite link to revoke
- Returns
- send_animation(chat_id: Union[int, str], animation: Union[Any, str], duration: Optional[int] = None, width: Optional[int] = None, height: Optional[int] = None, thumb: Optional[Union[Any, str]] = None, caption: Optional[str] = None, parse_mode: Optional[str] = None, caption_entities: Optional[List[telebot.types.MessageEntity]] = None, disable_notification: Optional[bool] = None, protect_content: Optional[bool] = None, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None) telebot.types.Message #
Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
Telegram documentation: https://core.telegram.org/bots/api#sendanimation
- Parameters
chat_id – Integer : Unique identifier for the message recipient — User or GroupChat id
animation – InputFile or String : Animation to send. You can either pass a file_id as String to resend an animation that is already on the Telegram server
duration – Integer : Duration of sent video in seconds
width – Integer : Video width
height – Integer : Video height
thumb – InputFile or String : Thumbnail of the file sent
caption – String : Animation caption (may also be used when resending animation by file_id).
parse_mode –
protect_content –
reply_to_message_id –
reply_markup –
disable_notification –
timeout –
caption_entities –
allow_sending_without_reply –
- Returns
- send_audio(chat_id: Union[int, str], audio: Union[Any, str], caption: Optional[str] = None, duration: Optional[int] = None, performer: Optional[str] = None, title: Optional[str] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, parse_mode: Optional[str] = None, disable_notification: Optional[bool] = None, timeout: Optional[int] = None, thumb: Optional[Union[Any, str]] = None, caption_entities: Optional[List[telebot.types.MessageEntity]] = None, allow_sending_without_reply: Optional[bool] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format.
Telegram documentation: https://core.telegram.org/bots/api#sendaudio
- Parameters
chat_id – Unique identifier for the message recipient
audio – Audio file to send.
caption –
duration – Duration of the audio in seconds
performer – Performer
title – Track name
reply_to_message_id – If the message is a reply, ID of the original message
reply_markup –
parse_mode –
disable_notification –
timeout –
thumb –
caption_entities –
allow_sending_without_reply –
protect_content –
- Returns
Message
- send_chat_action(chat_id: Union[int, str], action: str, timeout: Optional[int] = None) bool #
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 documentation: https://core.telegram.org/bots/api#sendchataction
- Parameters
chat_id –
action – One of the following strings: ‘typing’, ‘upload_photo’, ‘record_video’, ‘upload_video’, ‘record_audio’, ‘upload_audio’, ‘upload_document’, ‘find_location’, ‘record_video_note’, ‘upload_video_note’.
timeout –
- Returns
API reply. :type: boolean
- send_contact(chat_id: Union[int, str], phone_number: str, first_name: str, last_name: Optional[str] = None, vcard: Optional[str] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Use this method to send phone contacts.
Telegram documentation: https://core.telegram.org/bots/api#sendcontact
- Parameters
chat_id – Integer or String : Unique identifier for the target chat or username of the target channel
phone_number – String : Contact’s phone number
first_name – String : Contact’s first name
last_name – String : Contact’s last name
vcard – String : Additional data about the contact in the form of a vCard, 0-2048 bytes
disable_notification –
reply_to_message_id –
reply_markup –
timeout –
allow_sending_without_reply –
protect_content –
- Returns
- send_dice(chat_id: Union[int, str], emoji: Optional[str] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Use this method to send dices.
Telegram documentation: https://core.telegram.org/bots/api#senddice
- Parameters
chat_id –
emoji –
disable_notification –
reply_to_message_id –
reply_markup –
timeout –
allow_sending_without_reply –
protect_content –
- Returns
Message
- send_document(chat_id: Union[int, str], document: Union[Any, str], reply_to_message_id: Optional[int] = None, caption: Optional[str] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, parse_mode: Optional[str] = None, disable_notification: Optional[bool] = None, timeout: Optional[int] = None, thumb: Optional[Union[Any, str]] = None, caption_entities: Optional[List[telebot.types.MessageEntity]] = None, allow_sending_without_reply: Optional[bool] = None, visible_file_name: Optional[str] = None, disable_content_type_detection: Optional[bool] = None, data: Optional[Union[Any, str]] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Use this method to send general files.
Telegram documentation: https://core.telegram.org/bots/api#senddocument
- Parameters
chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
document – (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 using multipart/form-data
reply_to_message_id – If the message is a reply, ID of the original message
caption – Document caption (may also be used when resending documents by file_id), 0-1024 characters after entities parsing
reply_markup –
parse_mode – Mode for parsing entities in the document caption
disable_notification – Sends the message silently. Users will receive a notification with no sound.
timeout –
thumb – InputFile or String : 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 thumbnail’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, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>
caption_entities –
allow_sending_without_reply –
visible_file_name – allows to define file name that will be visible in the Telegram instead of original file name
disable_content_type_detection – Disables automatic server-side content type detection for files uploaded using multipart/form-data
data – function typo miss compatibility: do not use it
protect_content –
- Returns
API reply.
- send_game(chat_id: Union[int, str], game_short_name: str, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Used to send the game.
Telegram documentation: https://core.telegram.org/bots/api#sendgame
- Parameters
chat_id –
game_short_name –
disable_notification –
reply_to_message_id –
reply_markup –
timeout –
allow_sending_without_reply –
protect_content –
- Returns
- send_invoice(chat_id: Union[int, str], title: str, description: str, invoice_payload: str, provider_token: str, currency: str, prices: List[telebot.types.LabeledPrice], start_parameter: Optional[str] = None, photo_url: Optional[str] = None, photo_size: Optional[int] = None, photo_width: Optional[int] = None, photo_height: Optional[int] = None, need_name: Optional[bool] = None, need_phone_number: Optional[bool] = None, need_email: Optional[bool] = None, need_shipping_address: Optional[bool] = None, send_phone_number_to_provider: Optional[bool] = None, send_email_to_provider: Optional[bool] = None, is_flexible: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, provider_data: Optional[str] = None, timeout: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, max_tip_amount: Optional[int] = None, suggested_tip_amounts: Optional[List[int]] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Sends invoice.
Telegram documentation: https://core.telegram.org/bots/api#sendinvoice
- Parameters
chat_id – Unique identifier for the target private chat
title – Product name
description – Product description
invoice_payload – Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
provider_token – Payments provider token, obtained via @Botfather
currency – Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies
prices – Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
start_parameter – Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
photo_url – URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
photo_size – Photo size
photo_width – Photo width
photo_height – Photo height
need_name – Pass True, if you require the user’s full name to complete the order
need_phone_number – Pass True, if you require the user’s phone number to complete the order
need_email – Pass True, if you require the user’s email to complete the order
need_shipping_address – Pass True, if you require the user’s shipping address to complete the order
is_flexible – Pass True, if the final price depends on the shipping method
send_phone_number_to_provider – Pass True, if user’s phone number should be sent to provider
send_email_to_provider – Pass True, if user’s email address should be sent to provider
disable_notification – Sends the message silently. Users will receive a notification with no sound.
reply_to_message_id – If the message is a reply, ID of the original message
reply_markup – A JSON-serialized object for an inline keyboard. If empty, one ‘Pay total price’ button will be shown. If not empty, the first button must be a Pay button
provider_data – A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
timeout –
allow_sending_without_reply –
max_tip_amount – The maximum accepted amount for tips in the smallest units of the currency
suggested_tip_amounts – A JSON-serialized array of suggested amounts of tips in the smallest units of the currency. 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.
protect_content –
- Returns
- send_location(chat_id: Union[int, str], latitude: float, longitude: float, live_period: Optional[int] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, disable_notification: Optional[bool] = None, timeout: Optional[int] = None, horizontal_accuracy: Optional[float] = None, heading: Optional[int] = None, proximity_alert_radius: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Use this method to send point on the map.
Telegram documentation: https://core.telegram.org/bots/api#sendlocation
- Parameters
chat_id –
latitude –
longitude –
live_period –
reply_to_message_id –
reply_markup –
disable_notification –
timeout –
horizontal_accuracy –
heading –
proximity_alert_radius –
allow_sending_without_reply –
protect_content –
- Returns
API reply.
- send_media_group(chat_id: Union[int, str], media: List[Union[telebot.types.InputMediaAudio, telebot.types.InputMediaDocument, telebot.types.InputMediaPhoto, telebot.types.InputMediaVideo]], disable_notification: Optional[bool] = None, protect_content: Optional[bool] = None, reply_to_message_id: Optional[int] = None, timeout: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None) List[telebot.types.Message] #
Send a group of photos or videos as an album. On success, an array of the sent Messages is returned.
Telegram documentation: https://core.telegram.org/bots/api#sendmediagroup
- Parameters
chat_id –
media –
disable_notification –
protect_content –
reply_to_message_id –
timeout –
allow_sending_without_reply –
- Returns
- send_message(chat_id: Union[int, str], text: str, parse_mode: Optional[str] = None, entities: Optional[List[telebot.types.MessageEntity]] = None, disable_web_page_preview: Optional[bool] = None, disable_notification: Optional[bool] = None, protect_content: Optional[bool] = None, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None) telebot.types.Message #
Use this method to send text messages.
Warning: Do not send more than about 4000 characters each message, otherwise you’ll risk an HTTP 414 error. If you must send more than 4000 characters, use the split_string or smart_split function in util.py.
Telegram documentation: https://core.telegram.org/bots/api#sendmessage
- Parameters
chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
text – Text of the message to be sent
parse_mode – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
entities – List of special entities that appear in message text, which can be specified instead of parse_mode
disable_web_page_preview – Disables link previews for links in this message
disable_notification – Sends the message silently. Users will receive a notification with no sound.
protect_content – If True, the message content will be hidden for all users except for the target user
reply_to_message_id – If the message is a reply, ID of the original message
allow_sending_without_reply – Pass True, if the message should be sent even if the specified replied-to message is not found
reply_markup – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
timeout –
- Returns
API reply.
- send_photo(chat_id: Union[int, str], photo: Union[Any, str], caption: Optional[str] = None, parse_mode: Optional[str] = None, caption_entities: Optional[List[telebot.types.MessageEntity]] = None, disable_notification: Optional[bool] = None, protect_content: Optional[bool] = None, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None) telebot.types.Message #
Use this method to send photos. On success, the sent Message is returned.
Telegram documentation: https://core.telegram.org/bots/api#sendphoto
- Parameters
chat_id –
photo –
caption –
parse_mode –
caption_entities –
disable_notification –
protect_content –
reply_to_message_id –
allow_sending_without_reply –
reply_markup –
timeout –
- Returns
Message
- send_poll(chat_id: Union[int, str], question: str, options: List[str], is_anonymous: Optional[bool] = None, type: Optional[str] = None, allows_multiple_answers: Optional[bool] = None, correct_option_id: Optional[int] = None, explanation: Optional[str] = None, explanation_parse_mode: Optional[str] = None, open_period: Optional[int] = None, close_date: Optional[Union[int, datetime.datetime]] = None, is_closed: Optional[bool] = None, disable_notification: Optional[bool] = False, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, allow_sending_without_reply: Optional[bool] = None, timeout: Optional[int] = None, explanation_entities: Optional[List[telebot.types.MessageEntity]] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Sends a poll.
Telegram documentation: https://core.telegram.org/bots/api#sendpoll
- Parameters
chat_id –
question –
options – array of str with answers
is_anonymous –
type –
allows_multiple_answers –
correct_option_id –
explanation –
explanation_parse_mode –
open_period –
close_date –
is_closed –
disable_notification –
reply_to_message_id –
allow_sending_without_reply –
reply_markup –
timeout –
explanation_entities –
protect_content –
- Returns
- send_sticker(chat_id: Union[int, str], sticker: Union[Any, str], reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, disable_notification: Optional[bool] = None, timeout: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, protect_content: Optional[bool] = None, data: Optional[Union[Any, str]] = None) telebot.types.Message #
Use this method to send .webp stickers.
Telegram documentation: https://core.telegram.org/bots/api#sendsticker
- Parameters
chat_id –
sticker –
data –
reply_to_message_id –
reply_markup –
disable_notification – to disable the notification
timeout – timeout
allow_sending_without_reply –
protect_content –
data – function typo miss compatibility: do not use it
- Returns
API reply.
- send_venue(chat_id: Union[int, str], latitude: float, longitude: float, title: str, address: str, foursquare_id: Optional[str] = None, foursquare_type: Optional[str] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, google_place_id: Optional[str] = None, google_place_type: Optional[str] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Use this method to send information about a venue.
Telegram documentation: https://core.telegram.org/bots/api#sendvenue
- Parameters
chat_id – Integer or String : Unique identifier for the target chat or username of the target channel
latitude – Float : Latitude of the venue
longitude – Float : Longitude of the venue
title – String : Name of the venue
address – String : Address of the venue
foursquare_id – String : Foursquare identifier of the venue
foursquare_type – Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
disable_notification –
reply_to_message_id –
reply_markup –
timeout –
allow_sending_without_reply –
google_place_id –
google_place_type –
protect_content –
- Returns
- send_video(chat_id: Union[int, str], video: Union[Any, str], duration: Optional[int] = None, width: Optional[int] = None, height: Optional[int] = None, thumb: Optional[Union[Any, str]] = None, caption: Optional[str] = None, parse_mode: Optional[str] = None, caption_entities: Optional[List[telebot.types.MessageEntity]] = None, supports_streaming: Optional[bool] = None, disable_notification: Optional[bool] = None, protect_content: Optional[bool] = None, reply_to_message_id: Optional[int] = None, allow_sending_without_reply: Optional[bool] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None, data: Optional[Union[Any, str]] = None) telebot.types.Message #
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
Telegram documentation: https://core.telegram.org/bots/api#sendvideo
- Parameters
chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
video – Video to send. You can either pass a file_id as String to resend a video that is already on the Telegram servers, or upload a new video file using multipart/form-data.
duration – Duration of sent video in seconds
width – Video width
height – Video height
thumb – 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 thumbnail’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, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
caption – Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing
parse_mode – Mode for parsing entities in the video caption
caption_entities –
supports_streaming – Pass True, if the uploaded video is suitable for streaming
disable_notification – Sends the message silently. Users will receive a notification with no sound.
protect_content –
reply_to_message_id – If the message is a reply, ID of the original message
allow_sending_without_reply –
reply_markup –
timeout –
data – function typo miss compatibility: do not use it
- send_video_note(chat_id: Union[int, str], data: Union[Any, str], duration: Optional[int] = None, length: Optional[int] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, disable_notification: Optional[bool] = None, timeout: Optional[int] = None, thumb: Optional[Union[Any, str]] = None, allow_sending_without_reply: Optional[bool] = None, protect_content: Optional[bool] = None) telebot.types.Message #
- 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.
Telegram documentation: https://core.telegram.org/bots/api#sendvideonote
- Parameters
chat_id – Integer : Unique identifier for the message recipient — User or GroupChat id
data – InputFile or String : Video note to send. You can either pass a file_id as String to resend a video that is already on the Telegram server
duration – Integer : Duration of sent video in seconds
length – Integer : Video width and height, Can’t be None and should be in range of (0, 640)
reply_to_message_id –
reply_markup –
disable_notification –
timeout –
thumb – InputFile or String : Thumbnail of the file sent
allow_sending_without_reply –
protect_content –
- Returns
- send_voice(chat_id: Union[int, str], voice: Union[Any, str], caption: Optional[str] = None, duration: Optional[int] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, parse_mode: Optional[str] = None, disable_notification: Optional[bool] = None, timeout: Optional[int] = None, caption_entities: Optional[List[telebot.types.MessageEntity]] = None, allow_sending_without_reply: Optional[bool] = None, protect_content: Optional[bool] = None) telebot.types.Message #
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.
Telegram documentation: https://core.telegram.org/bots/api#sendvoice
- Parameters
chat_id – Unique identifier for the message recipient.
voice –
caption –
duration – Duration of sent audio in seconds
reply_to_message_id –
reply_markup –
parse_mode –
disable_notification –
timeout –
caption_entities –
allow_sending_without_reply –
protect_content –
- Returns
Message
- set_chat_administrator_custom_title(chat_id: Union[int, str], user_id: int, custom_title: str) bool #
Use this method to set a custom title for an administrator in a supergroup promoted by the bot.
Telegram documentation: https://core.telegram.org/bots/api#setchatadministratorcustomtitle
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
user_id – Unique identifier of the target user
custom_title – New custom title for the administrator; 0-16 characters, emoji are not allowed
- Returns
True on success.
- set_chat_description(chat_id: Union[int, str], description: Optional[str] = None) bool #
Use this method to change the description of a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Telegram documentation: https://core.telegram.org/bots/api#setchatdescription
- Parameters
chat_id – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
description – Str: New chat description, 0-255 characters
- Returns
True on success.
- set_chat_permissions(chat_id: Union[int, str], permissions: telebot.types.ChatPermissions) bool #
Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights.
Telegram documentation: https://core.telegram.org/bots/api#setchatpermissions
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
permissions – New default chat permissions
- Returns
True on success
- set_chat_photo(chat_id: Union[int, str], photo: Any) bool #
Use this method to set a new profile photo for the chat. Photos can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#setchatphoto
- Parameters
chat_id – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
photo – InputFile: New chat photo, uploaded using multipart/form-data
- Returns
- set_chat_sticker_set(chat_id: Union[int, str], sticker_set_name: str) telebot.types.StickerSet #
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#setchatstickerset
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
sticker_set_name – Name of the sticker set to be set as the group sticker set
- Returns
API reply.
- set_chat_title(chat_id: Union[int, str], title: str) bool #
Use this method to change the title of a chat. Titles can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.
Telegram documentation: https://core.telegram.org/bots/api#setchattitle
- Parameters
chat_id – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
title – New chat title, 1-255 characters
- Returns
- set_game_score(user_id: Union[int, str], score: int, force: Optional[bool] = None, chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, disable_edit_message: Optional[bool] = None) Union[telebot.types.Message, bool] #
Sets the value of points in the game to a specific user.
Telegram documentation: https://core.telegram.org/bots/api#setgamecore
- Parameters
user_id –
score –
force –
chat_id –
message_id –
inline_message_id –
disable_edit_message –
- Returns
- set_my_commands(commands: List[telebot.types.BotCommand], scope: Optional[telebot.types.BotCommandScope] = None, language_code: Optional[str] = None) bool #
Use this method to change the list of the bot’s commands.
Telegram documentation: https://core.telegram.org/bots/api#setmycommands
- Parameters
commands – List of BotCommand. At most 100 commands can be specified.
scope – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
language_code – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
- Returns
- set_state(user_id: int, state: Union[int, str], chat_id: Optional[int] = None) None #
Sets a new state of a user.
- Parameters
user_id –
state – new state. can be string or integer.
chat_id –
- set_sticker_position_in_set(sticker: str, position: int) bool #
Use this method to move a sticker in a set created by the bot to a specific position . Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#setstickerpositioninset
- Parameters
sticker –
position –
- Returns
- set_sticker_set_thumb(name: str, user_id: int, thumb: Optional[Union[Any, str]] = None)#
Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#setstickersetthumb
- Parameters
name – Sticker set name
user_id – User identifier
thumb –
- set_update_listener(listener)#
- set_webhook(url=None, certificate=None, max_connections=None, allowed_updates=None, ip_address=None, drop_pending_updates=None, timeout=None)#
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#setwebhook
- Parameters
url – HTTPS url to send updates to. Use an empty string to remove webhook integration
certificate – Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details.
max_connections – 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 – A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used.
ip_address – The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS
drop_pending_updates – Pass True to drop all pending updates
timeout – Integer. Request connection timeout
- Returns
API reply.
- setup_middleware(middleware: telebot.handler_backends.BaseMiddleware)#
Register middleware
- Parameters
middleware – Subclass of telebot.handler_backends.BaseMiddleware
- Returns
None
- shipping_query_handler(func, **kwargs)#
Shipping request handler
- Parameters
func –
kwargs –
- Returns
- stop_bot()#
- stop_message_live_location(chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None, timeout: Optional[int] = None) telebot.types.Message #
Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before live_period expires
Telegram documentation: https://core.telegram.org/bots/api#stopmessagelivelocation
- Parameters
chat_id –
message_id –
inline_message_id –
reply_markup –
timeout –
- Returns
- stop_poll(chat_id: Union[int, str], message_id: int, reply_markup: Optional[Union[telebot.types.InlineKeyboardMarkup, telebot.types.ReplyKeyboardMarkup, telebot.types.ReplyKeyboardRemove, telebot.types.ForceReply]] = None) telebot.types.Poll #
Stops a poll.
Telegram documentation: https://core.telegram.org/bots/api#stoppoll
- Parameters
chat_id –
message_id –
reply_markup –
- Returns
- stop_polling()#
- unban_chat_member(chat_id: Union[int, str], user_id: int, only_if_banned: Optional[bool] = False) bool #
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.
Telegram documentation: https://core.telegram.org/bots/api#unbanchatmember
- Parameters
chat_id – Unique identifier for the target group or username of the target supergroup or channel (in the format @username)
user_id – Unique identifier of the target user
only_if_banned – Do nothing if the user is not banned
- Returns
True on success
- unban_chat_sender_chat(chat_id: Union[int, str], sender_chat_id: Union[int, str]) bool #
Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#unbanchatsenderchat
- Params
- Parameters
chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
sender_chat_id – Unique identifier of the target sender chat
- Returns
True on success.
- unpin_all_chat_messages(chat_id: Union[int, str]) bool #
Use this method to unpin a all pinned messages in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#unpinallchatmessages
- Parameters
chat_id – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
- Returns
- unpin_chat_message(chat_id: Union[int, str], message_id: Optional[int] = None) bool #
Use this method to unpin specific pinned message in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#unpinchatmessage
- Parameters
chat_id – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
message_id – Int: Identifier of a message to unpin
- Returns
- upload_sticker_file(user_id: int, png_sticker: Union[Any, str]) telebot.types.File #
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success.
Telegram documentation: https://core.telegram.org/bots/api#uploadstickerfile
- Parameters
user_id –
png_sticker –
- Returns
- property user: telebot.types.User#
The User object representing this bot. Equivalent to bot.get_me() but the result is cached so only one API call is needed
custom_filters file#
- class telebot.custom_filters.AdvancedCustomFilter#
Bases:
abc.ABC
Simple Custom Filter base class. Create child class with check() method. Accepts two parameters, returns bool: True - filter passed, False - filter failed. message: Message class text: Filter value given in handler
- check(message, text)#
Perform a check.
- class telebot.custom_filters.ChatFilter#
Bases:
telebot.custom_filters.AdvancedCustomFilter
Check whether chat_id corresponds to given chat_id.
Example: @bot.message_handler(chat_id=[99999])
- check(message, text)#
Perform a check.
- key = 'chat_id'#
- class telebot.custom_filters.ForwardFilter#
Bases:
telebot.custom_filters.SimpleCustomFilter
Check whether message was forwarded from channel or group.
Example:
@bot.message_handler(is_forwarded=True)
- check(message)#
Perform a check.
- key = 'is_forwarded'#
- class telebot.custom_filters.IsAdminFilter(bot)#
Bases:
telebot.custom_filters.SimpleCustomFilter
Check whether the user is administrator / owner of the chat.
Example: @bot.message_handler(chat_types=[‘supergroup’], is_chat_admin=True)
- check(message)#
Perform a check.
- key = 'is_chat_admin'#
- class telebot.custom_filters.IsDigitFilter#
Bases:
telebot.custom_filters.SimpleCustomFilter
Filter to check whether the string is made up of only digits.
Example: @bot.message_handler(is_digit=True)
- check(message)#
Perform a check.
- key = 'is_digit'#
- class telebot.custom_filters.IsReplyFilter#
Bases:
telebot.custom_filters.SimpleCustomFilter
Check whether message is a reply.
Example:
@bot.message_handler(is_reply=True)
- check(message)#
Perform a check.
- key = 'is_reply'#
- class telebot.custom_filters.LanguageFilter#
Bases:
telebot.custom_filters.AdvancedCustomFilter
Check users language_code.
Example:
@bot.message_handler(language_code=[‘ru’])
- check(message, text)#
Perform a check.
- key = 'language_code'#
- class telebot.custom_filters.SimpleCustomFilter#
Bases:
abc.ABC
Simple Custom Filter base class. Create child class with check() method. Accepts only message, returns bool value, that is compared with given in handler.
- check(message)#
Perform a check.
- class telebot.custom_filters.StateFilter(bot)#
Bases:
telebot.custom_filters.AdvancedCustomFilter
Filter to check state.
Example: @bot.message_handler(state=1)
- check(message, text)#
Perform a check.
- key = 'state'#
- class telebot.custom_filters.TextContainsFilter#
Bases:
telebot.custom_filters.AdvancedCustomFilter
Filter to check Text message. key: text
Example: # Will respond if any message.text contains word ‘account’ @bot.message_handler(text_contains=[‘account’])
- check(message, text)#
Perform a check.
- key = 'text_contains'#
- class telebot.custom_filters.TextFilter(equals: Optional[str] = None, contains: Optional[Union[list, tuple]] = None, starts_with: Optional[Union[str, list, tuple]] = None, ends_with: Optional[Union[str, list, tuple]] = None, ignore_case: bool = False)#
Bases:
object
Advanced text filter to check (types.Message, types.CallbackQuery, types.InlineQuery, types.Poll)
example of usage is in examples/custom_filters/advanced_text_filter.py
- check(obj: Union[telebot.types.Message, telebot.types.CallbackQuery, telebot.types.InlineQuery, telebot.types.Poll])#
- class telebot.custom_filters.TextMatchFilter#
Bases:
telebot.custom_filters.AdvancedCustomFilter
Filter to check Text message. key: text
Example: @bot.message_handler(text=[‘account’])
- check(message, text)#
Perform a check.
- key = 'text'#
- class telebot.custom_filters.TextStartsFilter#
Bases:
telebot.custom_filters.AdvancedCustomFilter
Filter to check whether message starts with some text.
Example: # Will work if message.text starts with ‘Sir’. @bot.message_handler(text_startswith=’Sir’)
- check(message, text)#
Perform a check.
- key = 'text_startswith'#
Synchronous storage for states#
- class telebot.storage.StateContext(obj, chat_id, user_id)#
Bases:
object
Class for data.
- class telebot.storage.StateMemoryStorage#
Bases:
telebot.storage.base_storage.StateStorageBase
- delete_state(chat_id, user_id)#
Delete state for a particular user.
- get_data(chat_id, user_id)#
Get data for a user in a particular chat.
- get_interactive_data(chat_id, user_id)#
- get_state(chat_id, user_id)#
- reset_data(chat_id, user_id)#
Reset data for a particular user in a chat.
- save(chat_id, user_id, data)#
- set_data(chat_id, user_id, key, value)#
Set data for a user in a particular chat.
- set_state(chat_id, user_id, state)#
Set state for a particular user.
! Note that you should create a record if it does not exist, and if a record with state already exists, you need to update a record.
- class telebot.storage.StatePickleStorage(file_path='./.state-save/states.pkl')#
Bases:
telebot.storage.base_storage.StateStorageBase
- convert_old_to_new()#
Use this function to convert old storage to new storage. This function is for people who was using pickle storage that was in version <=4.3.1.
- create_dir()#
Create directory .save-handlers.
- delete_state(chat_id, user_id)#
Delete state for a particular user.
- get_data(chat_id, user_id)#
Get data for a user in a particular chat.
- get_interactive_data(chat_id, user_id)#
- get_state(chat_id, user_id)#
- read()#
- reset_data(chat_id, user_id)#
Reset data for a particular user in a chat.
- save(chat_id, user_id, data)#
- set_data(chat_id, user_id, key, value)#
Set data for a user in a particular chat.
- set_state(chat_id, user_id, state)#
Set state for a particular user.
! Note that you should create a record if it does not exist, and if a record with state already exists, you need to update a record.
- update_data()#
- class telebot.storage.StateRedisStorage(host='localhost', port=6379, db=0, password=None, prefix='telebot_')#
Bases:
telebot.storage.base_storage.StateStorageBase
This class is for Redis storage. This will work only for states. To use it, just pass this class to: TeleBot(storage=StateRedisStorage())
- delete_record(key)#
Function to delete record from database. It has nothing to do with states. Made for backend compatibility
- delete_state(chat_id, user_id)#
Delete state for a particular user in a chat.
- get_data(chat_id, user_id)#
Get data of particular user in a particular chat.
- get_interactive_data(chat_id, user_id)#
Get Data in interactive way. You can use with() with this function.
- get_record(key)#
Function to get record from database. It has nothing to do with states. Made for backend compatibility
- get_state(chat_id, user_id)#
Get state of a user in a chat.
- get_value(chat_id, user_id, key)#
Get value for a data of a user in a chat.
- reset_data(chat_id, user_id)#
Reset data of a user in a chat.
- save(chat_id, user_id, data)#
- set_data(chat_id, user_id, key, value)#
Set data without interactive data.
- set_record(key, value)#
Function to set record to database. It has nothing to do with states. Made for backend compatibility
- set_state(chat_id, user_id, state)#
Set state for a particular user in a chat.
- class telebot.storage.StateStorageBase#
Bases:
object
- delete_state(chat_id, user_id)#
Delete state for a particular user.
- get_data(chat_id, user_id)#
Get data for a user in a particular chat.
- get_state(chat_id, user_id)#
- reset_data(chat_id, user_id)#
Reset data for a particular user in a chat.
- save(chat_id, user_id, data)#
- set_data(chat_id, user_id, key, value)#
Set data for a user in a particular chat.
- set_state(chat_id, user_id, state)#
Set state for a particular user.
! Note that you should create a record if it does not exist, and if a record with state already exists, you need to update a record.
handler_backends file#
- class telebot.handler_backends.BaseMiddleware#
Bases:
object
Base class for middleware. Your middlewares should be inherited from this class.
- post_process(message, data, exception)#
- pre_process(message, data)#
- class telebot.handler_backends.CancelUpdate#
Bases:
object
Class for canceling updates. Just return instance of this class in middleware to skip update. Update will skip handler and execution of post_process in middlewares.
- class telebot.handler_backends.FileHandlerBackend(handlers=None, filename='./.handler-saves/handlers.save', delay=120)#
Bases:
telebot.handler_backends.HandlerBackend
- clear_handlers(handler_group_id)#
- static dump_handlers(handlers, filename, file_mode='wb')#
- get_handlers(handler_group_id)#
- load_handlers(filename=None, del_file_after_loading=True)#
- register_handler(handler_group_id, handler)#
- static return_load_handlers(filename, del_file_after_loading=True)#
- save_handlers()#
- start_save_timer()#
- class telebot.handler_backends.HandlerBackend(handlers=None)#
Bases:
object
Class for saving (next step|reply) handlers
- clear_handlers(handler_group_id)#
- get_handlers(handler_group_id)#
- register_handler(handler_group_id, handler)#
- class telebot.handler_backends.MemoryHandlerBackend(handlers=None)#
Bases:
telebot.handler_backends.HandlerBackend
- clear_handlers(handler_group_id)#
- get_handlers(handler_group_id)#
- load_handlers(filename, del_file_after_loading)#
- register_handler(handler_group_id, handler)#
- class telebot.handler_backends.RedisHandlerBackend(handlers=None, host='localhost', port=6379, db=0, prefix='telebot', password=None)#
Bases:
telebot.handler_backends.HandlerBackend
- clear_handlers(handler_group_id)#
- get_handlers(handler_group_id)#
- register_handler(handler_group_id, handler)#
- class telebot.handler_backends.SkipHandler#
Bases:
object
Class for skipping handlers. Just return instance of this class in middleware to skip handler. Update will go to post_process, but will skip execution of handler.
- class telebot.handler_backends.State#
Bases:
object
- class telebot.handler_backends.StatesGroup#
Bases:
object