Answer the question
In order to leave comments, you need to log in
How to fix callable Telegram Api Bot error in Python?
When you click "Select product" an error occurs and the bot stops what's wrong? :(
import telebot
#from telebot import *
from telebot import types
import config
bot = telebot.TeleBot(config.token)
@bot.message_handler(commands=['start'])
def send_welcome(message):
markup = types.ReplyKeyboardMarkup(True)
markup.add('Томск', 'Новосибирск')
msg = bot.send_message(message.chat.id, 'Выбери город', reply_markup=markup)
bot.register_next_step_handler(msg, choose_city)
def choose_city(message):
if (message.text == 'Томск'):
markup = types.ReplyKeyboardMarkup(True)
markup.add('Выбрать товар')
markup.add('Главное меню')
msg = bot.send_message(message.chat.id, 'Томск. Нажми выбрать товар', reply_markup=markup)
bot.register_next_step_handler(msg, 'choose_tsk, menu')
elif (message.text == 'Новосибирск'):
markup = types.ReplyKeyboardMarkup(True)
markup.add('Выбрать товар')
markup.add('Главное меню')
msg = bot.send_message(message.chat.id, 'Новосибирск. Нажми выбрать товар', reply_markup=markup)
bot.register_next_step_handler(msg, 'choose_nsk, menu')
@bot.message_handler(regexp='Главное меню')
def menu(message):
markup = types.ReplyKeyboardMarkup(True)
markup.row('Томск', 'Новосибирск')
msg = bot.send_message(message.chat.id, 'Главное меню, выберите город', reply_markup=markup)
bot.register_next_step_handler(msg, choose_city)
@bot.message_handler(regexp='Томск')
def choose_tsk(message):
if (message.text == 'Выбрать товар'):
markup = types.ReplyKeyboardMarkup(True)
markup.add('Ягоды')
markup.add('Главное меню')
msg = bot.send_message(message.chat.id, 'Томск. Выберите товар из списка', reply_markup=markup)
msg()
@bot.message_handler(regexp='Новосибирск')
def choose_nsk(message):
if (message.text == 'Выбрать товар'):
markup = types.ReplyKeyboardMarkup(True)
markup.add('Ягоды')
markup.add('Главное меню')
msg = bot.send_message(message.chat.id, 'Новосибирск. Выберите товар из списка', reply_markup=markup)
msg()
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
You need to know recursion .
When you know, you will need to write a function that:
1. Determines if there is a next nesting level and if there is, then selects this level and calls itself with this level.
2. If there is no next level, then returns the content from the current level.
Because you do not have a response to such a message, and you also need to put a handler before the choose_city function
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question