Back to Blog
TPY (Telebot Creator) Advanced TPY

Advanced TPY Command Techniques: Chaining and Scheduling

Advanced TPY Command Techniques

1. Command Chaining with runCommand

Command chaining allows you to execute one command from within another. This is useful for creating modular code and reusing functionality across different commands.

PYTHON
// In your /start command
bot.sendMessage("Welcome! Let me check your account status...");
runCommand("/checkStatus");

// The /checkStatus command runs automatically after

2. Delayed Execution with runCommandAfter

Sometimes you want to execute a command after a delay. The runCommandAfter function lets you schedule commands to run later, perfect for reminders and timed actions.

PYTHON
// Schedule a reminder
bot.sendMessage("I'll remind you in 5 minutes!");
runCommandAfter("/sendReminder", 300000); // 300,000 ms = 5 minutes

3. Multi-Step Commands with handleNextCommand

Guide users through complex workflows by capturing their next message and processing it with a specific command.

PYTHON
// Ask for user input
bot.sendMessage("Please enter your email address:");
handleNextCommand("/processEmail");

// The /processEmail command will receive what the user types next

4. Working with User Data

Store and retrieve user information across sessions using User properties. This is essential for creating personalized experiences.

PYTHON
// Store user data
User.setProperty("balance", 1000);
User.setProperty("membership", "premium");

// Retrieve user data
var userBalance = User.getProperty("balance");
var userTier = User.getProperty("membership");
bot.sendMessage("Your balance: $" + userBalance + "\nMembership: " + userTier);

5. Conditional Logic in Commands

Make your commands smarter with conditional statements that adapt based on user data or input.

PYTHON
var userStatus = User.getProperty("status");

if (userStatus === "premium") {
    bot.sendMessage("Welcome back, premium member! Here are your exclusive features...");
} else if (userStatus === "trial") {
    bot.sendMessage("Welcome! You have " + (7 - daysUsed) + " days left in your trial.");
} else {
    bot.sendMessage("Please upgrade to access this feature.");
}

Learn More

For more advanced techniques, visit the official documentation:

🔗 Telebot Creator Documentation

Best Practice

Always validate user input and handle edge cases. Use try-catch blocks when working with external APIs or performing complex operations.

📚 Source

This tutorial is based on the official Telebot Creator Documentation. Visit their site for the most up-to-date information and advanced guides.

Share this tutorial