B
B
bacbkofrancua2022-01-14 11:54:14
Python
bacbkofrancua, 2022-01-14 11:54:14

Problem writing a bot in python via pytelegrambotapi?

import telebot
from telebot import types
from telebot.types import InlineKeyboardMarkup

bot = telebot.TeleBot('token')

@bot.message_handler(commands=['start'])
def get_info(message):
keyboard = types.InlineKeyboardMarkup()
key_buy = types.InlineKeyboardButton(text='Paid', callback_data='/buy')
key_free = types.InlineKeyboardButton(text='Free', callback_data='/free')
keyboard.add(key_buy, key_free)
bot.send_message(message. chat.id,'I'm online. Which subscription will you use?\n Paid subscription (129 RUB/month) or free subscription is available. For details write /help.',reply_markup=keyboard)

@bot.callback_query_handler(func = lambda call: True)
def subscribe(call):
if call.data == '/buy':
send = bot.send_message(call.message.chat.id, 'Bla a')
bot.register_next_step_handler(send, subscribe2) Throws from here
elif call.data == '/free':
bot.send_message(call.message.chat.id, 'You are using the free version, but you can always buy the paid version from us. Details about it: /help.')
bot.answer_callback_query(callback_query_id=call .id)
def subscribe2(call): Here
keyb = types.InlineKeyboardMarkup()
key_no = types.InlineKeyboardButton(text='No', callback_data='no')
key_yes = types.InlineKeyboardButton(text='Yes', callback_data=' yes')
keyb.add(key_yes, key_no)
bot.send_message(call.message.chat.id, 'You have chosen to buy a subscription. It costs 129 rubles per month.\nAre you sure?', reply_markup=keyb)
if call.data == 'yes':
bot.send_message(call .message.chat.id, 'BUY')
elif call.data == 'no':
bot.send_message(call.message.chat.id, 'free')
bot.answer_callback_query(callback_query_id=call.id)
bot.polling ()

The bot should ask a question with the keyboard about the subscription, after clicking on the Paid button, a confirmation opens, after clicking on the Yes button, the following function should be displayed, but it is not displayed. Please point out the error.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question