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.

Попередження

A full list of methods can be found in the appropriate section of the documentation

class aiogram.client.bot.Bot(token: str, session: BaseSession | None = None, parse_mode: str | None = None, disable_web_page_preview: bool | None = None, protect_content: bool | None = None, default: DefaultBotProperties | None = None)[source]

Bases: object

__init__(token: str, session: BaseSession | None = None, parse_mode: str | None = None, disable_web_page_preview: bool | None = None, protect_content: bool | None = None, default: DefaultBotProperties | None = None) None[source]

Bot class

Параметри:
  • 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.

  • default – Default bot properties. If specified it will be propagated into the API methods at runtime.

Викликає:

TokenValidationError – When token has invalid format this exception will be raised

property token: str
property id: int

Get bot ID from token

Повертає:

context(auto_close: bool = True) AsyncIterator[Bot][source]

Generate bot context

Параметри:

auto_close – close session on exit

Повертає:

async me() User[source]

Cached alias for getMe method

Повертає:

async download_file(file_path: str, destination: BinaryIO | Path | str | None = None, timeout: int = 30, chunk_size: int = 65536, seek: bool = True) BinaryIO | None[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.

Параметри:
  • 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 None

  • timeout – 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: str | Downloadable, destination: BinaryIO | Path | str | None = None, timeout: int = 30, chunk_size: int = 65536, seek: bool = True) BinaryIO | None[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.

Параметри:
  • file – file_id or Downloadable object

  • destination – Filename, file path or instance of io.IOBase. For e.g. io.BytesIO, defaults to None

  • timeout – 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