0

Как можно сделать так, чтобы если text == 'расписание', появлялись кнопки с днями недели?

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
MAIN_KEYBOARD = [['Расписание', 'Домашка']]
def text_action(update, context):
    text = update.message.text.lower()
    cid = update.effective_chat.id
    if text == 'расписание':
        pass```
2
  • Для изменения используйте метод edit_message
    – Violet
    9 июл 2021 в 10:28
  • Покажите весь код
    – MyZik
    9 июл 2021 в 13:08

1 ответ 1

1
def chunks(l, n):
    n = max(1, n)
    return list((l[i:i + n] for i in range(0, len(l), n)))


def create_markup(group_id, update):
    buttons = []

    if group_id == 0:
       buttons += ['кнопка1','кнопка2',...]
    elif group_id == 1:
       buttons += ['кнопка1','кнопка2',...]
    ...
    keyboard = [KeyboardButton(button) for button in buttons]
    if len(keyboard) > 3:
        keyboard = chunks(keyboard, 3)
    else:
        keyboard = [keyboard]
    markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
    return markup

def second_step(update, context):
    if text == '...':
            markup = create_markup(group_id=0, update=update)
            context.bot.send_message(chat_id=update.message.chat_id,
                                     text='...',
                                     reply_markup=markup)
    elif text == '...':
            markup = create_markup(group_id=1, update=update)
            context.bot.send_message(chat_id=update.message.chat_id,
                                     text='...',
                                     reply_markup=markup)
1
  • Иван Борисов, спасибо большое!
    – Ann_S 123
    14 июл 2021 в 12:37

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.