Pytdbot¶
Python bots and userbots on TDLib — async, typed, and a bit nicer than calling Telegram by hand.
Your first bot¶
You need a token from @BotFather and api_id / api_hash from my.telegram.org. files_directory is TDLib’s database — one live client per folder.
/start greets the sender by name, shows typing, then edits the message. The reply lives on the Message you already have.
import asyncio
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",
)
@client.on_message()
async def start(c: Client, message: types.Message):
if message.text != "/start":
return
sent = await message.reply_text(
f"Hey {await message.mention(parse_mode='html')}",
parse_mode="html",
)
async with message.action("typing"):
await asyncio.sleep(1)
await sent.edit_text("What can I do for you?")
asyncio.run(client.run())
From here: sending, keyboards, plugins. TDLib names (getChat, sendMessage) are in the API reference.