@kuchkaroffshavkat

Не показывает другую клавиатуру. Что делать?

import telebot
from telebot import types

bot = telebot.TeleBot('token')

@bot.message_handler(commands=['start', 'help'])

def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
    btn1 = types.KeyboardButton('Top 15')
    btn2 = types.KeyboardButton('Check')
    markup.add(btn1, btn2)
    bot.send_message(message.chat.id, "Hi", reply_markup=markup)
@bot.message_handler(content_types=['text'])
def message_reply(message):
    if message.text == 'Top 15':
        bot.send_message(message.chat.id, 'District of Columbia $5.283')

@bot.message_handler(content_types=['text'])
def message_reply(message):
    if message.text == 'Check':
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
        btn3 = types.KeyboardButton('NORTHEAST')
        btn4 = types.KeyboardButton('MIDWEST')
        btn5 = types.KeyboardButton('SOUTH-EAST')
        btn6 = types.KeyboardButton('SOUTH-WEST')
        btn7 = types.KeyboardButton('WEST')
        markup.add(btn3, btn4, btn5, btn6, btn7)
        bot.send_message(message.chat.id, 'Choose your region!', reply_markup=markup)
    elif message.text == 'NORTHEAST':
        bot.send_message(message.chat.id, '55')

bot.polling(none_stop=True)
  • Вопрос задан
  • 52 просмотра
Решения вопроса 3
@Gold_doe
Не уверен, но зачем у вас два хендлера?
объедините все под один, иначе когда вы нажимаете на кнопку срабатывает только первый
@bot.message_handler(content_types=['text'])
def message_reply(message):
    if message.text == 'Top 15':
         bot.send_message(message.chat.id, 'District of Columbia $5.283')
    elif message.text == 'Check':
         markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
         btn3 = types.KeyboardButton('NORTHEAST')
         btn4 = types.KeyboardButton('MIDWEST')
         btn5 = types.KeyboardButton('SOUTH-EAST')
         btn6 = types.KeyboardButton('SOUTH-WEST')
         btn7 = types.KeyboardButton('WEST')
         markup.add(btn3, btn4, btn5, btn6, btn7)
         bot.send_message(message.chat.id, 'Choose your region!', reply_markup=markup) 
    elif message.text == 'NORTHEAST':
         bot.send_message(message.chat.id, '55')

bot.polling(none_stop=True)
Ответ написан
Комментировать
@Dmitry403
handler(content_types=['text']) может быть только один.
@bot.message_handler(content_types=['text'])
Ответ написан
Комментировать
Lord_of_Rings
@Lord_of_Rings
Python developer
import telebot
from telebot import types

bot = telebot.TeleBot('token')

@bot.message_handler(commands=['start', 'help'])

def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
    btn1 = types.KeyboardButton('Top 15')
    btn2 = types.KeyboardButton('Check')
    markup.add(btn1, btn2)
    bot.send_message(message.chat.id, "Hi", reply_markup=markup)

@bot.message_handler(content_types=['text'])
def message_reply(message):
    if message.text == 'Top 15':
        bot.send_message(message.chat.id, 'District of Columbia $5.283')
    elif message.text == 'Check':
        markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
        btn3 = types.KeyboardButton('NORTHEAST')
        btn4 = types.KeyboardButton('MIDWEST')
        btn5 = types.KeyboardButton('SOUTH-EAST')
        btn6 = types.KeyboardButton('SOUTH-WEST')
        btn7 = types.KeyboardButton('WEST')
        markup.add(btn3, btn4, btn5, btn6, btn7)
        bot.send_message(message.chat.id, 'Choose your region!', reply_markup=markup)
    elif message.text == 'NORTHEAST':
        bot.send_message(message.chat.id, '55')

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

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

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