Bot#
Bot instance can be created from aiogram.Bot
(from aiogram import Bot
) and
you can’t use methods without instance of bot with configured token.
This class has aliases for all methods and named in lower_camel_case
.
For example sendMessage
named send_message
and has the same specification with all class-based methods.
Warning
A full list of methods can be found in the appropriate section of the documentation
- class aiogram.client.bot.Bot(token: str, session: Optional[BaseSession] = None, parse_mode: Optional[str] = None, disable_web_page_preview: Optional[bool] = None, protect_content: Optional[bool] = None)[source]
Bases:
ContextInstanceMixin
[Bot
]- __init__(token: str, session: Optional[BaseSession] = None, parse_mode: Optional[str] = None, disable_web_page_preview: Optional[bool] = None, protect_content: Optional[bool] = None) None [source]
Bot class
- Parameters:
token – Telegram Bot token Obtained from @BotFather
session – HTTP Client session (For example AiohttpSession). If not specified it will be automatically created.
parse_mode – Default parse mode. If specified it will be propagated into the API methods at runtime.
disable_web_page_preview – Default disable_web_page_preview mode. If specified it will be propagated into the API methods at runtime.
protect_content – Default protect_content mode. If specified it will be propagated into the API methods at runtime.
- Raises:
TokenValidationError – When token has invalid format this exception will be raised
- property token: str
- property id: int
Get bot ID from token
- Returns:
- context(auto_close: bool = True) AsyncIterator[Bot] [source]
Generate bot context
- Parameters:
auto_close –
- Returns:
- async download_file(file_path: str, destination: Optional[Union[BinaryIO, Path, str]] = None, timeout: int = 30, chunk_size: int = 65536, seek: bool = True) Optional[BinaryIO] [source]
Download file by file_path to destination.
If you want to automatically create destination (
io.BytesIO
) use default value of destination and handle result of this method.- Parameters:
file_path – File path on Telegram server (You can get it from
aiogram.types.File
)destination – Filename, file path or instance of
io.IOBase
. For e.g.io.BytesIO
, defaults to Nonetimeout – Total timeout in seconds, defaults to 30
chunk_size – File chunks size, defaults to 64 kb
seek – Go to start of file when downloading is finished. Used only for destination with
typing.BinaryIO
type, defaults to True
- async download(file: Union[str, Downloadable], destination: Optional[Union[BinaryIO, Path, str]] = None, timeout: int = 30, chunk_size: int = 65536, seek: bool = True) Optional[BinaryIO] [source]
Download file by file_id or Downloadable object to destination.
If you want to automatically create destination (
io.BytesIO
) use default value of destination and handle result of this method.- Parameters:
file – file_id or Downloadable object
destination – Filename, file path or instance of
io.IOBase
. For e.g.io.BytesIO
, defaults to Nonetimeout – Total timeout in seconds, defaults to 30
chunk_size – File chunks size, defaults to 64 kb
seek – Go to start of file when downloading is finished. Used only for destination with
typing.BinaryIO
type, defaults to True