From a36d0815b4a1752195ca1fbce852a2366566ff96 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 22 Jan 2023 21:41:45 +0300 Subject: [PATCH] telegram inline button error --- .../python/telegram-inline-button-error.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 content/posts/2023/python/telegram-inline-button-error.md diff --git a/content/posts/2023/python/telegram-inline-button-error.md b/content/posts/2023/python/telegram-inline-button-error.md new file mode 100644 index 0000000..8f3a403 --- /dev/null +++ b/content/posts/2023/python/telegram-inline-button-error.md @@ -0,0 +1,40 @@ +--- +title: "❌ Ошибка 400 при добавлении InlineKeyboardButton в Telegram" +date: 2023-01-22T21:33:01+03:00 +draft: false +tags: [tips, telegram, python] +--- + +## Ошибка 400 + +```text +Error code: 400. +Description: Bad Request: can't parse inline keyboard button: +Text buttons are unallowed in the inline keyboard +``` + +Имеем такой код + +```python +keyboard = types.InlineKeyboardMarkup() +types_buttons = ( + types.InlineKeyboardButton('\U0001f44d'), + types.InlineKeyboardButton('\U0001f44e'), +) + +for type_button in types_buttons: + keyboard.add(type_button) + +bot.send_message(message.chat.id, 'text', reply_markup=keyboard) +``` + +## Решение + +Инлайн кнопки должны иметь хотя бы одно опциональное поле: +`callback_data`, `url`, `switch_inline_query` и т.д. +You must use exactly one of the optional fields +(https://core.telegram.org/bots/api#inlinekeyboardbutton) + +Если нужны текстовые кнопки, необходимо использовать класс `ReplyKeyboardMarkup`. + +Thanks [GrAnd](https://ru.stackoverflow.com/a/1354497).