Python Bots
Build Telegram bots in Python on the NxCreate runtime.
NxCreate can also run bots written in Python.
Overview
A Python bot is built from separate commands. Each command has a trigger — like /start, a word the user types, or a button they tap — and some code that runs when that trigger happens.
You don't need to set up a bot or connect it to Telegram yourself — that part is already done. Your code just gets handed everything it needs about the message: who sent it, what they typed, and so on.
Command-based structure
This works differently from NxCreate's JavaScript bots. In JavaScript, you write one script that lists out every command by hand (bot.command('start', ...), bot.hears(...), and so on).
In Python, there is no single script. Each command is added on its own, separately, with its own trigger and its own code. You don't need to register it anywhere else — add the command and it just works.
Bot.runCommand().Bot / User / libs globals
Three ready-to-use names cover most of what a bot needs:
| Name | What it’s for |
|---|---|
Bot | Things that apply to the whole bot — saving settings, running another command, sending a delayed message, or messaging all your users at once. |
User | Saving information about one user, like their name or score. It automatically applies to whoever sent the current message, unless you say otherwise. |
libs | Small helpers — counters, random numbers, the current date and time, and a few others. |
u is the user's chat id — use it whenever a method asks for a chat id.Telegram methods
Send and edit messages with bot.sendMessage, bot.sendPhoto, bot.editMessageText, bot.answerCallbackQuery, and more — see Telegram Methods for the full list. Bold, links, and other formatting work automatically, so tags like <b> and <a href> show up correctly without extra setup.
Dedicated reference pages
- Bot Object — bot-wide data, running commands, scheduling, broadcasting.
- User Object — per-user data storage.
- libs Reference — counters, random values, date/time, webhook URLs.
- Telegram Methods — sending and editing messages, keyboards.