Skip to content

Plugins

Split handlers into modules under a folder. Pass types.Plugins into Client.

from pytdbot import Client, types

client = Client(
    token="BOT_TOKEN",
    api_id=0,
    api_hash="API_HASH",
    files_directory="BotDB",
    database_encryption_key="change-me",
    plugins=types.Plugins(
        folder="plugins/",
        # include=["rules", "admin.ban"],
        # exclude=["experimental"],
    ),
)
Arg Meaning
folder Directory to scan for *.py (recursive)
include If set, only these names relative to folder (rulesplugins/rules.py)
exclude If set (and no include), skip these names

Plugin module (plugins/ping.py) — decorate with Client.… (no client instance):

from pytdbot import Client, types, filters

private = filters.create(lambda _, m: m.chat_id > 0)

@Client.on_message(filters=private)
async def ping(c: Client, message: types.Message):
    if message.text == "/ping":
        await message.reply_text("pong")

Loaded when Client is constructed with plugins=…. The folder must be importable (usually run from the project root). Inside a plugin, reply_text is the same bound method as on a live client.

  • client.reload_plugins() — reload modules (dev only)
  • client.remove_handler(func) — drop one function