Answer the question
In order to leave comments, you need to log in
Telebot, script not working?
Run guys somebody this .
Some trifling mistake, I can't figure it out
Newbie in bots
POINT:
There is a message in the fucking function with inline buttons .
The easy function should respond to the user's choice.
But for some reason it doesn't work. I suspect it is because of bot.register_next_step_handler
import telebot
import config
from telebot import types
bot = telebot.TeleBot(config.TOKEN)
user_messages = []
user_location = ''
our_positions = dict()
our_positions['eclair'] = 'Эклер'
our_positions['chuck'] = 'Чак-чак'
our_positions['tiramisu'] = 'Тирамису'
#
#
@bot.message_handler(commands=['start'])
def welcome(message):
bot.send_message(message.chat.id, "Привет, {0.first_name} ! \nЯ бот для отправки заказов \nНапиши свою точку (местоположение)".format(message.from_user, bot.get_me()), parse_mode='html')
@bot.message_handler(content_types=['text'])
def first(message):
# keyboard
global user_location
user_location = message.text
markup = types.InlineKeyboardMarkup()
item1 = types.InlineKeyboardButton(text='Сделать заказ', callback_data='to_do_the_order')
item2 = types.InlineKeyboardButton(text='Изменить заказ', callback_data='to_change_the_order')
markup.add(item1, item2)
bot.send_message(message.chat.id, "Готово ! \nВыбери нужную кнопку", reply_markup=markup)
@bot.callback_query_handler(func = lambda call: True)
def answer(call):
if call.data == 'to_do_the_order':
msg = bot.send_message(call.message.chat.id, 'Сколько ' + our_positions['eclair'] + 'ов' + ' закажешь ?')
bot.register_next_step_handler(msg, sec_prod_question)
if call.data == 'to_change_the_order':
# keyboard
markup = types.InlineKeyboardMarkup()
item1 = types.InlineKeyboardButton(text='Все', callback_data='all')
item2 = types.InlineKeyboardButton(text='Эклер', callback_data='eclair')
item3 = types.InlineKeyboardButton(text='Чак-чак', callback_data='chuck')
item4 = types.InlineKeyboardButton(text='Тирамису', callback_data='tiramisu')
markup.add(item1, item2, item3, item4)
bot.send_message(call.message.chat.id, 'Какую позицию ты хочешь изменить ?', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def sec_prod_question(message):
user_messages.append(message.text) # ответ юзера на 1ый продукт
second_question = 'Сколько ' + our_positions['chuck'] + 'ов' +' нужно сегодня ?'
msg = bot.send_message(message.chat.id, second_question)
bot.register_next_step_handler(msg, third_prod_question)
@bot.message_handler(content_types=['text'])
def third_prod_question(message):
user_messages.append(message.text) # ответ юзера на 2ой продукт
second_question = 'Как насчёт ' + our_positions['tiramisu'] + 'у' + ' ?'
msg = bot.send_message(message.chat.id, second_question)
bot.register_next_step_handler(msg, fucking)
# bot.clear_step_handler(msg)
@bot.message_handler(content_types=['text'])
def fucking(message):
keyboard = types.InlineKeyboardMarkup()
key_yes = types.InlineKeyboardButton(text='Да', callback_data='yes')
keyboard.add(key_yes)
key_no = types.InlineKeyboardButton(text='Нет', callback_data='no')
keyboard.add(key_no)
question = 'Поч тут не работают кнопки ' + '?'
msg = bot.send_message(message.from_user.id, text=question, reply_markup=keyboard)
@bot.callback_query_handler(func = lambda call: True)
def easy(call):
if call.data == 'yes':
msg = bot.send_message(call.message.chat.id, 'Сколько закажешь ?')
else:
msg = bot.send_message(call.message.chat.id, 'Сколько не закажешь ?')
# RUN
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Because you have the same decorators everywhere
4
@bot.message_handler(content_types=['text']) text message handlers
and 2
@bot.callback_query_handler(func = lambda call: True) callback handlers
The code chooses the one that is higher, namely
@bot.callback_query_handler(func = lambda call: True)
def answer(call):
if call.data == 'to_do_the_order':
msg = bot.send_message(call.message.chat.id, 'Сколько ' + our_positions['eclair'] + 'ов' + ' закажешь ?')
bot.register_next_step_handler(msg, sec_prod_question)
if call.data == 'to_change_the_order':
# keyboard
markup = types.InlineKeyboardMarkup()
item1 = types.InlineKeyboardButton(text='Все', callback_data='all')
item2 = types.InlineKeyboardButton(text='Эклер', callback_data='eclair')
item3 = types.InlineKeyboardButton(text='Чак-чак', callback_data='chuck')
item4 = types.InlineKeyboardButton(text='Тирамису', callback_data='tiramisu')
markup.add(item1, item2, item3, item4)
bot.send_message(call.message.chat.id, 'Какую позицию ты хочешь изменить ?', reply_markup=markup)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question