N
N
Nika9802021-12-08 14:39:35
Python
Nika980, 2021-12-08 14:39:35

How to display more than ten Inline buttons?

I am writing a bot for telegrams, I brought out 10 buttons with the names of cities and what will come to the user when they are pressed, but I can’t do more than 10. I need 18 cities, but on button 11 it gives an error:

2021-12-08 14:37:09,572 (__init__.py:690 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: can't parse inline keyboard button: Text buttons are unallowed in the inline keyboard"

Here is the code:

import telebot;
from telebot import types;
bot = telebot.TeleBot('210***0343:AAFmK1GKAY************iTpY1eljQ')
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
    if message.text == "/start":
        bot.send_message(message.from_user.id, f"Привет,{message.from_user.first_name} рады Вас снова видеть в нашем магазине")
        markup = types.InlineKeyboardMarkup()
        button1 = types.InlineKeyboardButton('ОМСК ', callback_data='1')
        button2 = types.InlineKeyboardButton('КАЛАЧИНСК ', callback_data='2')
        markup = types.InlineKeyboardMarkup()
        button3 = types.InlineKeyboardButton('ТАТАРСК ', callback_data='3')
        button4 = types.InlineKeyboardButton('КОРМИЛОВКА ', callback_data='4')
        button5 = types.InlineKeyboardButton('ИСИЛЬКУЛЬ ', callback_data='5')
        button6 = types.InlineKeyboardButton('ТАВРИЧЕСКОЕ ', callback_data='6')
        markup = types.InlineKeyboardMarkup()
        button7 = types.InlineKeyboardButton('ТАРА ', callback_data='7')
        button8 = types.InlineKeyboardButton('ЛЮБИНО ', callback_data='8')
        markup = types.InlineKeyboardMarkup()
        button9 = types.InlineKeyboardButton('НАЗЫВАЕВСК ', callback_data='9')
        button10 = types.InlineKeyboardButton('ТЮКАЛИНСК ', callback_data='10')
        markup = types.InlineKeyboardMarkup()
        button11 = types.InlineKeyboardButton('БОЛЬШЕРЕЧЬЕ ', callbsck_data='11')
        button12 = types.InlineKeyboardButton('КРУТАЯ ГОРКА ', callback_data='12')
        markup.row(button1, button2)
        markup.row(button3, button4)
        markup.row(button5, button6)
        markup.row(button7, button8)
        markup.row(button9, button10)
        markup.row(button11, button12)
        bot.send_message(message.from_user.id, f"Выберите ГОРОД", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def query_handler(call):

    bot.answer_callback_query(callback_query_id=call.id)
    answer = ''
    if call.data == '1':
        answer = 'Выберите ТОВАР'
    if call.data == '2':
        answer = 'Выберите ТОВАР'
        bot.send_message(call.message.chat.id, answer)
    if call.data == '3':
        answer = 'Выберите ТОВАР'
    if call.data == '4':
        answer = 'Выберите ТОВАР'
        bot.send_message(call.message.chat.id, answer)
    if call.data == '5':
        answer = 'Выберите ТОВАР'
    if call.data == '6':
        answer = 'Выберите ТОВАР'
        bot.send_message(call.message.chat.id, answer)
    if call.data == '7':
        answer = 'Выберите ТОВАР'
    if call.data == '8':
        answer = 'Выберите ТОВАР'
        bot.send_message(call.message.chat.id, answer)
    if call.data == '9':
        answer = 'Выберите ТОВАР'
    if call.data == '10':
        answer = 'Выберите ТОВАР'
        bot.send_message(call.message.chat.id, answer)
    if call.data == '11':
        answer = 'Выберите ТОВАР'
    if call.data == '12':
        answer = 'Выберите ТОВАР'
        bot.send_message(call.message.chat.id, answer)
bot.polling(none_stop=True, interval=0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-12-08
@twistfire92

We carefully look at the line with the addition of the 11th button
button11 = types.InlineKeyboardButton('BIG ', callb s ck_data='11')
Be careful with the typos.
What is happening in your code below? Hell of a horror!!! Why so many repetitions?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question