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'
|
owner
|
int | None
|
Telegram ID of the bot's owner. Defaults to |
None
|
config
|
Config | None
|
Assembled config object. Defaults to |
None
|
config_path
|
str | Path
|
Path to the configuration file to load from if |
Path('config.json')
|
config_type
|
type[Config]
|
Config type/class to use if |
Config
|
api_id
|
int | None
|
Telegram API ID. Defaults to |
None
|
api_hash
|
str | None
|
Telegram API hash. Defaults to |
None
|
bot_token
|
str | None
|
Bot token. Defaults to |
None
|
workers
|
int
|
Number of maximum concurrent workers for handling updates. Defaults to
|
workers_cpu_count
|
locales_root
|
str | Path | None
|
Path to the root directory of locale files. Defaults to
|
None
|
plugins_root
|
str
|
Path to the root directory of plugins. Defaults to |
'plugins'
|
plugins_exclude
|
list[str] | None
|
List of plugins to exclude from loading. Defaults to
|
None
|
sleep_threshold
|
int
|
Threshold in seconds used by Pyrogram's internal scheduler for
auto-sleeping before flood-wait limits. Defaults to |
120
|
max_concurrent_transmissions
|
int | None
|
Maximum number of concurrent file transmissions.
Defaults to |
None
|
commands_source
|
dict[str, dict] | None
|
Source dictionary describing available bot commands.
Defaults to |
None
|
scoped_commands
|
bool | None
|
Whether commands should be registered per-scope. Defaults to
|
None
|
i18n_bot_info
|
bool
|
Whether to localize the bot's info (name/description) using i18n.
Defaults to |
False
|
scheduler
|
AsyncIOScheduler | BackgroundScheduler | None
|
Scheduler instance to attach to the
client for scheduled tasks. Defaults to |
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
|
scheduler_start
|
bool
|
Start the bot's scheduler. Defaults to |
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
|
True
|
exit_completely
|
bool
|
Execute |
True
|
scheduler_shutdown
|
bool
|
Shutdown the bot's scheduler. Defaults to |
True
|
scheduler_wait
|
bool
|
Wait for the scheduler tasks to finish. Defaults to |
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. |