D
D
damir4ig2020-06-21 21:03:10
Python
damir4ig, 2020-06-21 21:03:10

PyTelegramBotAPI How to make keyboard appear after certain text?

I have a keyboard 5eefa05b13c3f696419378.pngand I want that after a button is pressed, another keyboard and another function written by me come out. Tried if but keyboard didn't come out

# -*- coding: utf-8 -*-
import telebot                                                                          import config
from telebot import types

bot = telebot.TeleBot(config.token)

@bot.message_handler(commands=["start"])
def startKBoard(message):
    startKBoard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    Catalog = types.KeyboardButton(text="Каталог")
    Info = types.KeyboardButton(text="Инофрмация")
    startKBoard.add(Catalog, Info)
    bot.send_message(message.chat.id, "Добро пожаловать в магазин цифровых товаров", re>

@bot.message_handler(content_types=['text'])
def catalogchk(message):
    if message.text == "Каталог":
        def catalogKBoard(message):
           catalogKBoard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True)
           Steam = types.KeyboardButton(text="Steam")
           Origin = types.KeyboardButton(text="Origin")
           UPlay = types.KeyboardButton(text="UPlay")
           EpicGames = types.KeyboardButton(text="Epic Games")
           VPN = types.KeyboardButton(text="VPN")
           catalogKBoard.add(Steam, Origin, UPlay, EpicGames, VPN)
           bot.send_message(message.chat.id, "Выберите Раздел")

if __name__ == '__main__':
    bot.infinity_polling()
Help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-21
@damir4ig

Why are you making a function inside a function?
Do it like this

@bot.message_handler(content_types=['text'])
def catalogchk(message):
    if message.text == "Каталог":
        catalogKBoard = types.ReplyKeyboardMarkup(row_width=2, resize_keyboard=True)
        Steam = types.KeyboardButton(text="Steam")
        Origin = types.KeyboardButton(text="Origin")
        UPlay = types.KeyboardButton(text="UPlay")
        EpicGames = types.KeyboardButton(text="Epic Games")
        VPN = types.KeyboardButton(text="VPN")
        catalogKBoard.add(Steam, Origin, UPlay, EpicGames, VPN)
        bot.send_message(message.chat.id, "Выберите Раздел", reply_markup=catalogKBoard)

If you want to make separate functions for generating keyboards - do this:
def start_keyboard():
    keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    Catalog = types.KeyboardButton(text="Каталог")
    Info = types.KeyboardButton(text="Инофрмация")
    keyboard.add(Catalog, Info)
    return keyboard

def catalog_keyboard():
    keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    Steam = types.KeyboardButton(text="Steam")
    Origin = types.KeyboardButton(text="Origin")
    UPlay = types.KeyboardButton(text="UPlay")
    EpicGames = types.KeyboardButton(text="Epic Games")
    VPN = types.KeyboardButton(text="VPN")
    keyboard.add(Steam, Origin, UPlay, EpicGames, VPN)
    return keyboard

Usage:
bot.send_message(message.chat.id, "Сообщение", reply_markup=catalog_keyboard())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question