@ddd1111090909

Телеграм Бот не реагирует на нажатие кнопки 'услуги', что делать?

@bot.message_handler(commands=['start'])
def start(message):
      markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
      detailes = types.KeyboardButton('Детали о сервисе')
      services = types.KeyboardButton('Услуги')
      instruction = types.KeyboardButton('Инструкция')
      markup.add(detailes, services, instruction)
      bot.send_message(message.chat.id, 'Приветствуем вас!', reply_markup=markup)

@bot.message_handler()
def get_user_text(message):
    if message.text == 'Детали о сервисе':
        markup1 = types.ReplyKeyboardMarkup(resize_keyboard=True)
        back = types.KeyboardButton('Назад в меню')
        markup1.add(back)
        bot.send_message(message.chat.id, "fffff", reply_markup=markup1)
    elif message.text == 'Назад в меню':
           bot.send_message(message.chat.id, "Вы вернулись в меню", reply_markup=None)
           markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
           detailes = types.KeyboardButton('Детали о сервисе')
           services = types.KeyboardButton('Услуги')
           instruction = types.KeyboardButton('Инструкция')
           markup.add(detailes, services, instruction)
           bot.send_message(message.chat.id, 'Выберите информацию для отображения:', reply_markup=markup)


@bot.message_handler()
def get_user_text(message):
    if message.text == 'Услуги':
        markup2 = types.ReplyKeyboardMarkup(resize_keyboard=True)
        ps = types.KeyboardButton('fff')
        xb = types.KeyboardButton('lll')
        ap = types.KeyboardButton('sss')
        pm = types.KeyboardButton('ppp')
        back = types.KeyboardButton('Назад в меню')
        markup2.add(ps, xb, ap, pm, back)
        bot.send_message(message.chat.id, 'Выберите платформу', reply_markup=markup2)
    elif message.text == 'Назад в меню':
           bot.send_message(message.chat.id, "Вы вернулись в меню", reply_markup=None)
           markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
           detailes = types.KeyboardButton('Детали о сервисе')
           services = types.KeyboardButton('Услуги')
           instruction = types.KeyboardButton('Инструкция')
           markup.add(detailes, services, instruction)
           bot.send_message(message.chat.id, 'Выберите информацию для отображения:', reply_markup=markup)

bot.polling(none_stop=True)
  • Вопрос задан
  • 167 просмотров
Решения вопроса 1
@shamraimaxim
Изучаю Python Development, работы с БД и API
Если делаете интерактивное меню, одного метода с handler'ом content_types=['text'] будет достаточно, а вы сделали так что первый метод get_user_text(message), который первый, всегда будет хендлится даже если нету выполнения условия
import telebot
from telebot import types

bot = telebot.TeleBot("YOUR TOKEN")


@bot.message_handler(commands=['start'])
def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
    detailes = types.KeyboardButton('Детали о сервисе')
    services = types.KeyboardButton('Услуги')
    instruction = types.KeyboardButton('Инструкция')
    markup.add(detailes, services, instruction)
    bot.send_message(message.chat.id, 'Приветствуем вас!', reply_markup=markup)


@bot.message_handler(content_types=['text'])
def get_user_text(message):
    if message.text == 'Детали о сервисе':
        markup1 = types.ReplyKeyboardMarkup(resize_keyboard=True)
        back = types.KeyboardButton('Назад в меню')
        markup1.add(back)
        bot.send_message(message.chat.id, "fffff", reply_markup=markup1)

    elif message.text == 'Инструкция':
        bot.send_message(message.chat.id, "Инструкция: Пишите чистый код и"
                                          " делайте нормальные названия переменных!)")

    elif message.text == 'Услуги':
        markup2 = types.ReplyKeyboardMarkup(resize_keyboard=True)
        ps = types.KeyboardButton('fff')
        xb = types.KeyboardButton('lll')
        ap = types.KeyboardButton('sss')
        pm = types.KeyboardButton('ppp')
        back = types.KeyboardButton('Назад в меню')
        markup2.add(ps, xb, ap, pm, back)
        bot.send_message(message.chat.id, 'Выберите платформу', reply_markup=markup2)

    elif message.text == 'Назад в меню':
        bot.send_message(message.chat.id, "Вы вернулись в меню", reply_markup=None)
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
        detailes = types.KeyboardButton('Детали о сервисе')
        services = types.KeyboardButton('Услуги')
        instruction = types.KeyboardButton('Инструкция')
        markup.add(detailes, services, instruction)
        bot.send_message(message.chat.id, 'Выберите информацию для отображения:', reply_markup=markup)


bot.polling(none_stop=True)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы