Загрузка...

Problems with telegram bot # 2

Thread in Python created by nonstopblow Aug 27, 2020. 165 views

  1. nonstopblow
    nonstopblow Topic starter Aug 27, 2020 0 Jul 21, 2020
    Как сделать привязку клавиатуры?:

    условно в меню бота есть разделы

    выберите свой город

    >москва - допустим тыкаем по москве
    >питер
    >новоси

    выберите район москвы

    >Мск1
    >Мск2
    >Мск3

    как сделать их привязать между собой ?

    код:


    @bot.message_handler(content_types=['text'])
    def city(message):
    if message.chat.type == 'private':
    if message.text == 'По всем вопросам':
    bot.send_message(message.chat.id, '@miracleshelp')
    elif message.text == 'Выберите свой город':

    markup = types.InlineKeyboardMarkup(row_width=2)
    item1 = types.InlineKeyboardButton("Москва", callback_data='Moscow')
    item2 = types.InlineKeyboardButton("Санкт-Петербург", callback_data='Saint Petersburg')
    item3 = types.InlineKeyboardButton("Новосибирск", callback_data='Novosibirsk')

    markup.add(item1, item2, item3 )

    bot.send_message(message.chat.id, 'Отлично,выберите район', reply_markup=markup)

    @bot.message_handler(content_types=['text'])
    def Moscow (message):
    if message.text == 'Выберите свой район':

    markup = types.InlineKeyboardMarkup(row_width=2)
    item1 = types.InlineKeyboardButton("МСК 1", callback_data='msk1')
    item2 = types.InlineKeyboardButton("МСК 2", callback_data='msk2')
    item3 = types.InlineKeyboardButton("МСК 3", callback_data='msk3')

    markup.add(item1, item2, item3 )

    bot.send_message(message.chat.id, 'Отлично, выберите район', reply_markup=markup)
     
  2. wendee
    wendee Aug 27, 2020 Ntngjbif8durjrbntnvjcjdididif 67 Oct 13, 2018
    @bot.callback_query_handler(func=lambda call:True)
    def call_opros(call):
    if call.data == "first":
    bot.send_message(call.message.chat.id, text="Введите свой вопрос")
     
Top
Loading...