Skip to content

PyroClient

PyroClient

Bases: Client

__init__(name='bot_client', owner=None, config=None, config_path=Path('config.json'), config_type=Config, api_id=None, api_hash=None, bot_token=None, workers=workers_cpu_count, locales_root=None, plugins_root='plugins', plugins_exclude=None, sleep_threshold=120, max_concurrent_transmissions=None, commands_source=None, scoped_commands=None, i18n_bot_info=False, scheduler=None, **kwargs)

Parameters:

Name Type Description Default
name str

Name of the bot's client. Defaults to "bot_client".

'bot_client'
owner int | None

Telegram ID of the bot's owner. Defaults to None.

None
config Config | None

Assembled config object. Defaults to None, which will trigger reading from the file.

None
config_path str | Path

Path to the configuration file to load from if PyroClient.config is None. Defaults to Path("config.json").

Path('config.json')
config_type type[Config]

Config type/class to use if PyroClient.config is None. Defaults to Config.

Config
api_id int | None

Telegram API ID. Defaults to None, which will use the value from PyroClient.config.

None
api_hash str | None

Telegram API hash. Defaults to None, which will use the value from PyroClient.config.

None
bot_token str | None

Bot token. Defaults to None, which will use the value from PyroClient.config.

None
workers int

Number of maximum concurrent workers for handling updates. Defaults to min(32, cpu_count() + 4), unless overridden by PyroClient.config.

workers_cpu_count
locales_root str | Path | None

Path to the root directory of locale files. Defaults to None, which will resolve to Path("locale").

None
plugins_root str

Path to the root directory of plugins. Defaults to "plugins".

'plugins'
plugins_exclude list[str] | None

List of plugins to exclude from loading. Defaults to None, which will use the value from PyroClient.config.

None
sleep_threshold int

Threshold in seconds used by Pyrogram's internal scheduler for auto-sleeping before flood-wait limits. Defaults to 120.

120
max_concurrent_transmissions int | None

Maximum number of concurrent file transmissions. Defaults to None, which will use the value from PyroClient.config.

None
commands_source dict[str, dict] | None

Source dictionary describing available bot commands. Defaults to None, which will use the value from PyroClient.config.

None
scoped_commands bool | None

Whether commands should be registered per-scope. Defaults to None, which will use the value from PyroClient.config.

None
i18n_bot_info bool

Whether to localize the bot's info (name/description) using i18n. Defaults to False.

False
scheduler AsyncIOScheduler | BackgroundScheduler | None

Scheduler instance to attach to the client for scheduled tasks. Defaults to None.

None
**kwargs Any

Any other keyword arguments that will be passed to Pyrogram.

{}

add_command(command)

Add command to the bot's internal commands list

Parameters:

Name Type Description Default
command str

Command name to add.

required

collect_commands() async

Gather list of the bot's commands

Returns:

Type Description
list[CommandSet] | None

list[CommandSet]: List of the commands' sets.

register_commands(command_sets=None) async

Register commands stored in bot's 'commands' attribute

remove_commands(command_sets=None) async

Remove commands stored in bot's 'commands' attribute

start(register_commands=True, scheduler_start=True) async

Start the client.

This method connects the client to Telegram and, in case of new sessions, automatically manages the authorization process using an interactive prompt.

Parameters:

Name Type Description Default
register_commands bool

Register bot commands. Defaults to True.

True
scheduler_start bool

Start the bot's scheduler. Defaults to True.

True

Returns:

Name Type Description
Client None

The started client itself.

Raises:

Type Description
ConnectionError

In case you try to start an already started client.

stop(block=True, exit_completely=True, scheduler_shutdown=True, scheduler_wait=True) async

Stop the Client.

This method disconnects the client from Telegram and stops the underlying tasks.

Parameters:

Name Type Description Default
block bool

Blocks the code execution until the client has been stopped. It is useful with block=False in case you want to stop the own client within a handler in order not to cause a deadlock. Defaults to True.

True
exit_completely bool

Execute sys.exit() after the bot has exited. Defaults to True.

True
scheduler_shutdown bool

Shutdown the bot's scheduler. Defaults to True.

True
scheduler_wait bool

Wait for the scheduler tasks to finish. Defaults to True.

True

Returns:

Name Type Description
Client None

The stopped client itself.

Raises:

Type Description
ConnectionError

In case you try to stop an already stopped client.