API Reference

Version Info

bale.__version__

A string representation of the version. e.g. '1.0.0rc1'. This is based off of PEP 440.

Bot

class bale.Bot

This object represents a Bale Bot.

Parameters:
  • token (str) – Bot Token

  • updater (Optional[bale.Updater]) –

Note

When you create bot and run for first-step, use bale.Bot.delete_webhook() method in on_ready event.

listen(event_name)

Register a Event

add_event(event, function)

Register an Event with event name

remove_event(event, function=None)

Register an Event with event name

wait_for(event_name, *, check=None, timeout=None)

Wait for an event

property user

Represents the connected client. None if not logged in

Type:

Optional[bale.User]

await close()

Close http Events and bot

is_closed()

bool: Connection Status

await on_error(event_name, error)

a Event for get errors when exceptions

await get_bot()

Get bot information

Returns:

Bot User information.

Return type:

bale.User

Raises:

APIError – Get bot Failed.

await delete_webhook()

This service is used to remove the webhook set for the bot.

Returns:

True else False if not done

Return type:

bool

Raises:
  • Forbidden – You do not have permission to delete Webhook.

  • APIError – Delete webhook Failed.

await send_message(chat_id, text, *, components=None, reply_to_message_id=None)

This service is used to send text messages.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • text (str) – Text of the message to be sent. Max 4096 characters after entities parsing.

  • components (Optional[bale.Components | bale.RemoveComponents]) – Message Components

  • reply_to_message_id (Optional[str | int]) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

Returns:

The Message

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to send Message to this chat.

  • APIError – Send Message Failed.

await forward_message(chat_id, from_chat_id, message_id)

This service is used to send text messages.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • from_chat_id (str | int) – the chat where the original message was sent (or channel username in the format @channelusername).

  • message_id (int | str) – Message in the chat specified in from_chat_id.

Returns:

The Message

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to send Message to this chat.

  • APIError – Forward Message Failed.

await send_document(chat_id, document, *, caption=None, reply_to_message_id=None)

This service is used to send document.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • document (bytes | str | bale.Document) – File to send. Pass a file_id as String to send a file that exists on the Bale servers (recommended), pass an HTTP URL as a String for Bale to get a file from the Internet, or upload a new one.

  • caption (Optional[str]) – Document caption.

  • reply_to_message_id (Optional[str | int]) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

Returns:

The Message.

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to send Document to this chat.

  • APIError – Send Document Failed.

await send_photo(chat_id, photo, *, caption=None, reply_to_message_id=None)

This service is used to send photo.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • photo (bytes | str | bale.Photo) – Photo to send. Pass a file_id as String to send a file that exists on the Bale servers (recommended), pass an HTTP URL as a String for Bale to get a file from the Internet, or upload a new one.

  • caption (Optional[str]) – Photo caption.

  • reply_to_message_id (Optional[str | int]) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

Returns:

The Message.

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to Send Photo to chat.

  • APIError – Send photo Failed.

await send_audio(chat_id, audio, *, caption=None, reply_to_message_id=None)

This service is used to send Audio.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • audio (bytes | str | bale.Audio) – Audio file to send. Pass a file_id as String to send a file that exists on the Bale servers (recommended), pass an HTTP URL as a String for Bale to get a file from the Internet, or upload a new one.

  • caption (Optional[str]) – Audio caption.

  • reply_to_message_id (Optional[str | int]) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

Returns:

The Message.

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to Send Audio to chat.

  • APIError – Send Audio Failed.

await send_video(chat_id, video, *, caption=None, reply_to_message_id=None)

This service is used to send Video.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • video (bytes | str | bale.Photo) – Video to send. Pass a file_id as String to send a file that exists on the Bale servers (recommended), pass an HTTP URL as a String for Bale to get a file from the Internet, or upload a new one.

  • caption (Optional[str]) – Video caption.

  • reply_to_message_id (Optional[str | int]) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

Returns:

The Message.

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to Send Video to chat.

  • APIError – Send Video Failed.

await send_location(chat_id, location)

Use this method to send point on the map.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • location (bale.Location) – The Location.

Returns:

The Message.

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to send Location to this chat.

  • APIError – Send Location Failed.

await send_contact(chat_id, contact)

This service is used to send contact.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • contact (bale.ContactMessage) – The Contact.

Returns:

The Message.

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to send Contact Message to this chat.

  • APIError – Send Contact Message Failed.

await send_invoice(chat_id, title, description, provider_token, prices, *, photo_url=None, need_name=False, need_phone_number=False, need_email=False, need_shipping_address=False, is_flexible=True)

You can use this service to send money request messages.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • title (str) – Product name. 1- 32 characters.

  • description (str) – Product description. 1- 255 characters.

  • provider_token (str) – You can use 3 methods to receive money: 1.Card number 2. Port number and acceptor number 3. Wallet number “Bale”

  • prices (List[bale.Price]) – A list of prices.

  • photo_url (Optional[str]) – 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.

  • need_name (Optional[bool]) – Pass True, if you require the user’s full name to complete the order.

  • need_phone_number (Optional[bool]) – Pass True, if you require the user’s phone number to complete the order.

  • need_email (Optional[bool]) – Pass True, if you require the user’s email to complete the order.

  • need_shipping_address (Optional[bool]) – Pass True, if you require the user’s shipping address to complete the order.

  • is_flexible (Optional[bool]) – Pass True, if the final price depends on the shipping method.

Return type:

bale.Message

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to send Invoice to this chat.

  • APIError – Send Invoice Failed.

await edit_message(chat_id, message_id, text, *, components=None)

You can use this service to edit text messages that you have already sent through the arm.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • message_id (str | int) – Unique identifier for the message to edit.

  • text (str) – New text of the message, 1- 4096 characters after entities parsing.

  • components (Optional[bale.Components | bale.RemoveComponents]) – An object for an inline keyboard.

Raises:
  • NotFound – Invalid Message or Chat ID.

  • Forbidden – You do not have permission to Edit Message.

  • APIError – Edit Message Failed.

await delete_message(chat_id, message_id)

You can use this service to delete a message that you have already sent through the arm.

Warning

In Channel or Group:

If it is a group or channel Manager, it can delete a message from (group or channel).

In private message (PV):

If the message was sent by a bot, it can be deleted with this method

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • message_id (bale.Message) – Unique identifier for the message to delete.

Raises:
  • NotFound – Invalid Message or Chat ID.

  • Forbidden – You do not have permission to Delete Message.

  • APIError – Delete Message Failed.

await get_chat(chat_id)

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.).

Parameters:

chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

Returns:

The chat or None if not found.

Return type:

Optional[bale.Chat]

Raises:
  • Forbidden – You do not have permission to get Chat.

  • APIError – Get chat Failed.

await get_user(user_id)

This Method almost like bale.Bot.get_chat , but this a filter that only get user.

Parameters:

user_id (int) – user id

Returns:

The user or None if not found.

Return type:

Optional[bale.User]

Raises:
  • Forbidden – You do not have permission to get User.

  • APIError – Get user Failed.

await get_chat_member(chat_id, user_id)

Use this method to get information about a member of a chat. The method is only guaranteed to work for other users if the bot is an administrator in the chat.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • user_id (Optional[int | str]) – Unique identifier of the target user.

Returns:

The chat member of None if not found.

Return type:

Optional[bale.ChatMember]

Raises:
  • NotFound – Invalid Chat or User ID.

  • Forbidden – You do not have permission to get Chat Member.

  • APIError – Get chat member Failed.

await ban_chat_member(chat_id, user_id)

Use this method to ban a user from a group, supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first.

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • user_id (int | str) – Unique identifier of the target user.

Returns:

On success, True is returned.

Return type:

bool

Raises:
  • NotFound – Invalid Chat or User ID.

  • Forbidden – You do not have permission to ban Chat Member.

  • APIError – ban chat member Failed.

await get_chat_members_count(chat_id)

Use this method to get the number of members in a chat.

Parameters:

chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to get Members count of the Chat.

  • APIError – get Members count of the Chat Failed.

Returns:

The members count of the chat

Return type:

int

await get_chat_administrators(chat_id)

Use this method to get a list of administrators in a chat.

Parameters:

chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

Returns:

list of chat member.

Return type:

List[bale.ChatMember]

Raises:
  • NotFound – Invalid Chat ID.

  • Forbidden – You do not have permission to get Administrators of the Chat.

  • APIError – get Administrators of the Chat from chat Failed.

await get_file(file_id)

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 20 MB in size.

Parameters:

file_id (str) – Either the file identifier to get file information about.

Returns:

The content of the file

Return type:

bytes

Raises:
  • NotFound – Invalid file ID.

  • Forbidden – You do not have permission to download File.

  • APIError – download File Failed.

await invite_user(chat_id, user_id)

Invite user to the chat

Parameters:
  • chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

  • user_id (str | int) – Unique identifier for the target user.

Raises:
  • NotFound – Invalid Chat or User ID.

  • Forbidden – You do not have permission to Add user to Chat.

  • APIError – Invite user Failed.

await leave_chat(chat_id)

Use this method for your bot to leave a group, channel.

Parameters:

chat_id (str | int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).

Raises:
  • Forbidden – You do not have permission to Leave from chat.

  • APIError – Leave from chat Failed.

run(sleep_after_every_get_updates=None)

Run bot and https

Models

CallbackQuery

class bale.CallbackQuery

This object represents an incoming callback query from a callback button in an inline keyboard.

callback_id

Unique identifier for this query.

Type:

str

from_user

Sender.

Type:

bale.User

message

Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old.

Type:

bale.Message

inline_message_id

Identifier of the message sent via the bot in inline mode, that originated the query.

Type:

str

data

Data associated with the callback button. Be aware that the message, which originated the query, can contain no callback buttons with this data.

Type:

str

property user

Aliases for from_user

Chat

class bale.Chat

This object indicates a chat.

chat_id

Unique identifier for this chat.

Type:

str

type

Type of chat.

Type:

bale.ChatType

title

Title, for channels and group chats.

Type:

Optional[str]

username

Username, for private chats, supergroups and channels if available.

Type:

Optional[str]

first_name

First name of the other party in a private chat.

Type:

Optional[str]

last_name

Last name of the other party in a private chat.

Type:

Optional[str]

pinned_message

Pinned messages in chat. Defaults to None.

Type:

Optional[bale.Message]

Primary invite link, for groups and channel. Returned only in bale.Bot.get_chat().

Type:

Optional[str]

all_members_are_administrators

Does everyone have admin access?. Defaults to True. (for Group)

Type:

bool

property mention

Optional[str]

await send(text, components=None)

For the documentation of the arguments, please see bale.Bot.send_message().

await send_document(document, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_document().

await send_photo(photo, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_photo().

await send_video(video, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_video().

await send_audio(audio, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_audio().

await send_location(location)

For the documentation of the arguments, please see bale.Bot.send_location().

await send_contact(contact)

For the documentation of the arguments, please see bale.Bot.send_contact().

await send_invoice(title, description, provider_token, prices, *, photo_url=None, need_name=False, need_phone_number=False, need_email=False, need_shipping_address=False, is_flexible=True)

For the documentation of the arguments, please see bale.Bot.send_invoice()

await leave()

For the documentation of the method, please see bale.Bot.leave_chat().

await add_user(user)

For the documentation of the arguments, please see bale.Bot.invite_user().

await get_chat_member(user)

For the documentation of the arguments, please see bale.Bot.get_chat_member().

await ban_chat_member(user)

For the documentation of the arguments, please see bale.Bot.ban_chat_member().

await get_chat_members_count()

For the documentation of the arguments, please see bale.Bot.get_chat_members_count().

await get_chat_administrators()

For the documentation of the arguments, please see bale.Bot.get_chat_administrators().

Chat Type

class bale.ChatType

This object indicates a Chat Type.

is_private_chat()

bool: Return True if Chat Type is Private

is_group_chat()

bool: Return True if Chat Type is Group

is_channel_chat()

bool: Return True if Chat Type is Channel

User

class bale.User

This object represents a Bale user or bot.

user_id

Unique identifier for this user or bot.

Type:

int

is_bot

True, if this user is a bot.

Type:

bool

first_name

User’s or bot’s first name.

Type:

str

last_name

User’s or bot’s last name.

Type:

Optional[str]

username

User’s or bot’s username.

Type:

Optional[str]

property mention

User’s or bot’s mention with username.

Type:

Optional[str]

property chat_id

str

await send(text, components=None)

For the documentation of the arguments, please see bale.Bot.send_message().

await send_document(document, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_document().

await send_photo(photo, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_photo().

await send_video(video, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_video().

await send_audio(audio, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_audio().

await send_location(location)

For the documentation of the arguments, please see bale.Bot.send_location().

await send_contact(contact)

For the documentation of the arguments, please see bale.Bot.send_contact().

await send_invoice(title, description, provider_token, prices, *, photo_url=None, need_name=False, need_phone_number=False, need_email=False, need_shipping_address=False, is_flexible=True)

For the documentation of the arguments, please see bale.Bot.send_invoice()

Chat Member

Attributes
Methods
class bale.ChatMember

This object shows a member in chat

user

Information about the user.

Type:

bale.User

status

The member’s status in the chat.

Type:

bale.ChatMemberStatus

permissions

The member’s permissions in the chat.

Type:

bale.Permissions

await ban()

For the documentation of the arguments, please see bale.Bot.ban_chat_member().

Chat Member Status

class bale.ChatMemberStatus

This object shows member’s status in chat.

is_owner()

bool: Return True if Member is chat creator

is_admin()

bool: Return True if Member have admin status

is_member()

bool: Return True if Member haven’t any status

Message

class bale.Message

This object shows a message.

message_id

Unique message identifier inside this chat.

Type:

str

from_user

Sender of the message; empty for messages sent to channels. For backward compatibility, this will contain a fake sender user in non-channel chats, if the message was sent on behalf of a chat.

Type:

Optional[bale.User]

chat

Conversation the message belongs to.

Type:

bale.Chat

date

Date the message was sent in Unix time.

Type:

datetime.datetime

text

Message Content

Type:

Optional[str]

caption

Caption for the animation, audio, document, photo, video or voice.

Type:

Optional[str]

forward_from

For forwarded messages, sender of the original message.

Type:

Optional[bale.User]

forward_from_chat

For messages forwarded from channels or from anonymous administrators, information about the original sender chat.

Type:

Optional[bale.Chat]

reply_to_message

For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.

Type:

Optional[bale.Message]

contact

Message is a shared contact, information about the contact.

Type:

Optional[bale.ContactMessage]

location

Message is a shared location, information about the location.

Type:

Optional[bale.Location]

document

Message is a general file, information about the file.

Type:

Optional[bale.Document]

video

Message is a video, information about the video.

Type:

Optional[bale.Video]

audio

Message is an audio, information about the Audio.

Type:

Optional[bale.Audio]

new_chat_members

New members that were added to the group or supergroup and information about them (the bot itself may be one of these members). This list is empty if the message does not contain new chat members.

Type:

Optional[List[bale.User]]

left_chat_member

A member was removed from the group, information about them (this member may be the bot itself).

Type:

Optional[bale.User]

invoice

Message is an invoice for a payment, information about the invoice.

Type:

Optional[bale.Invoice]

property author

An alias for from_user

property attachment

Represents the message attachment. None if the message don’t have any attachments

Type:

Optional[bale.File]

property content

Represents the message content. None if the message don’t have text or caption

Type:

Optional[str]

property chat_id

Represents the Unique identifier of Conversation the message belongs to.

Type:

str | int

property reply_to_message_id

Represents the Unique identifier of Original message, if the message has been replied. None If the message is not replied

Type:

Optional[str]

await reply(text, *, components=None)

For the documentation of the arguments, please see bale.Bot.send_message().

await forward(chat_id)

For the documentation of the arguments, please see bale.Bot.forward_message().

await reply_document(document, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_document().

await reply_photo(photo, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_photo().

await reply_video(video, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_video().

await reply_audio(audio, *, caption=None)

For the documentation of the arguments, please see bale.Bot.send_audio().

await edit(text, *, components=None)

For the documentation of the arguments, please see bale.Bot.edit_message()

await delete()

For the documentation of the arguments, please see bale.Bot.delete_message().

Update

class bale.Update

This object represents an incoming update.

update_id

The update’s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.

Type:

int

callback_query

New incoming callback query.

Type:

Optional[bale.CallbackQuery]

message

New incoming message of any kind - text, photo, sticker, etc.

Type:

Optional[bale.Message]

edited_message

New version of a message that is known to the bot and was edited.

Type:

Optional[bale.Message]

Update Type

class bale.UpdateType

This object indicates an Update Type.

is_message_update()

bool: Return True if Update Type is Message

is_callback_update()

bool: Return True if Update Type is Callback

is_edited_message()

bool: Return True if Update Type is Edited Message

is_unknown_update()

bool: Return True if Update Type is Unknown

UI

Note

You must be use Component Models for design ui of messages.

Components

class bale.Components

This object shows a Component.

property menu_keyboards

Represents the MenuKeyboards list.

Type:

str

property inline_keyboards

Represents the InlineKeyboards list.

Type:

str

add_menu_keyboard(menu_keyboard, row=1)

Use this method to add MenuKeyboard component.

Parameters:
  • menu_keyboard (bale.MenuKeyboard) – The Component you want to add

  • row (int) – The Component row number

remove_menu_keyboard(menu_keyboard, row=1)

Use this method to remove MenuKeyboard component.

Parameters:
  • menu_keyboard (bale.MenuKeyboard) – The Component you want to remove

  • row (int) – The Component row number

add_inline_keyboard(inline_keyboard, row=1)

Use this method to add InlineKeyboard component.

Parameters:
  • inline_keyboard (bale.InlineKeyboard) – The Component you want to add

  • row (int) – The Component row number

remove_inline_keyboard(inline_keyboard, row=1)

Use this method to remove InlineKeyboard component.

Parameters:
  • inline_keyboard (bale.InlineKeyboard) – The Component you want to remove

  • row (int) – The Component row number

Inline Keyboard

class bale.InlineKeyboard

This object shows an inline keyboard (within the message).

text

Label text on the button.

Type:

str

callback_data

If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot’s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. Defaults to None.

Type:

str

url

HTTP url to be opened when the button is pressed. Defaults to None.

Type:

str

switch_inline_query

If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot’s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. Defaults to None.

Type:

str

switch_inline_query_current_chat

If set, pressing the button will insert the bot’s username and the specified inline query in the current chat’s input field. Can be empty, in which case only the bot’s username will be inserted. Defaults to None.

Type:

str

Remove Menu Keyboard Components

class bale.RemoveMenuKeyboard

This object shows a Removed menu keyboard(s).


Caption:

use RemoveMenuKeyboard to delete Menu keyboard Components.

… components = bale.RemoveMenuKeyboard() await message.reply(…, components=components)

Attachment Models

File

class bale.File

This object shows a Base File Class.

file_type

Type of the file.

Type:

str

file_id

Identifier for this file, which can be used to download or reuse the file.

Type:

str

file_size

File size in bytes.

Type:

Optional[int]

mime_type

MIME type of the file as defined by sender.

Type:

Optional[str]

extra

The rest of the file information.

Type:

Optional[dict]

.. note::

You can get more information in file with :param:`extra`

property type

a Shortcut for use bale.File.file_type

Type:

str

property base_file

Represents the Base File Class of this file

Type:

bale.File

await get()

For the documentation of the arguments, please see bale.Bot.get_file().

await save_to_memory(out)

Download this file into memory. out needs to be supplied with a io.BufferedIOBase, the file contents will be saved to that object using the io.BufferedIOBase.write() method.

Parameters:

out (io.BinaryIO) – A file-like object. Must be opened for writing in binary mode.

Audio

class bale.Audio

This object shows a Audio.

file_id

Identifier for this file, which can be used to download or reuse the file.

Type:

str

duration

Duration of the audio in seconds as defined by sender.

Type:

int

file_size

File size in bytes.

Type:

int

mime_type

MIME type of the file as defined by sender.

Type:

Optional[str]

title

Title of the audio as defined by sender or by audio tags.

Type:

Optional[str]

Contact Message

class bale.ContactMessage

This object shows a Message Contact.

phone_number
Type:

int

first_name
Type:

str

last_name
Type:

Optional[str]

Document

class bale.Document

This object shows a Document.

file_id

Identifier for this file, which can be used to download or reuse the file.

Type:

str

file_name

Original filename as defined by sender.

Type:

Optional[str]

mime_type

MIME type of the file as defined by sender.

Type:

Optional[str]

file_size

File size in bytes.

Type:

Optional[int]

Photo

class bale.Photo

This object shows a Photo.

file_id

Identifier for this file, which can be used to download or reuse the file.

Type:

str

width

Photo width as defined by sender.

Type:

int

height

Photo height as defined by sender.

Type:

str

file_size

File size in bytes.

Type:

int

Location

Attributes
class bale.Location

This object shows an end

longitude

Location longitude

Type:

int

latitude

Location latitude

Type:

int

export location link from map

Type:

str

Payment Models

Invoice

class bale.Invoice

This object shows Invoice

title

Invoice title.

Type:

str

description

Invoice Description.

Type:

str

start_parameter

No Description.

Type:

str

currency

No Description.

Type:

str

total_amount

No Description.

Type:

int

Price

Attributes
class bale.Price

This object shows a Price

label

Label Price.

Type:

Optional[str]

amount

Amount Price.

Type:

Optional[int]

Event Reference

Event Types

class bale.EventType

This object represents an Event Type.

READY

bale.on_ready()

Type:

str

BEFORE_READY

bale.on_before_ready()

Type:

str

UPDATE

bale.on_update()

Type:

str

MESSAGE

bale.on_message()

Type:

str

EDITED_MESSAGE

bale.on_edited_message()

Type:

str

CALLBACK

bale.on_callback()

Type:

str

MEMBER_CHAT_JOIN

bale.on_member_chat_join()

Type:

str

MEMBER_CHAT_LEAVE

bale.on_member_chat_leave()

Type:

str

Note

You must be use bale.EventType for general events

from bale import Bale, EventType

bot = bale.Bot(token="Your Token")

@bot.listen(EventType.Update)
async def when_receive_update(update):
    ...

Before Ready

bale.on_before_ready()

Called Before the bale.Updater stars.

Ready

bale.on_ready()

Called when a bot is ready.

Update

bale.on_update(update)

Called when a Update Sent.

Parameters:

update (bale.Update) – The update

Message

bale.on_message(message)

Called when a Message Sent.

Parameters:

message (bale.Message) – The message

Edited Message

bale.on_edited_message(message)

Called when a Message Edited.

Parameters:

message (bale.Message) – The message

Callback

bale.on_callback(callback)

Called when a Callback Sent.

Parameters:

callback (bale.CallbackQuery) – The callback

Member Chat Join

bale.on_member_chat_join(message, chat, user)

When a user joins the chat.

Parameters:

Member Chat Leave

bale.on_member_chat_leave(message, chat, user)

When a user leaves the chat.

Parameters:

Exceptions

The following exceptions are thrown by the library.

exception bale.BaleError(message)

Base exception class for python-bale-bot

message

The text of the error. Could be an None.

Type:

str

exception bale.InvalidToken(message)

An exception where the server says the Token is Invalid

exception bale.APIError(error_code, message)

Exception that’s raised for when status code 400 occurs and Error is Unknown. Subclass of BaleError

exception bale.NetworkError(message)

Exception that’s raised when the connection is closed for reasons that could not be handled internally.

exception bale.TimeOut
exception bale.NotFound(message=None)

Exception that’s raised for when status code 404 occurs. Subclass of BaleError

exception bale.Forbidden

Exception that’s raised for when status code 403 occurs. Subclass of BaleError

exception bale.RateLimited

Exception that’s raised for when Rate Limits. Subclass of BaleError

exception bale.HTTPException(error)

Exception that’s raised when an HTTP request operation fails.