Compare commits

...

2 Commits

Author SHA1 Message Date
a36d0815b4
telegram inline button error 2023-01-22 21:41:45 +03:00
d5dc142230
change title 2023-01-22 21:41:17 +03:00
2 changed files with 41 additions and 1 deletions

View File

@ -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).

View File

@ -3,7 +3,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css"> <link rel="stylesheet" type="text/css" href="/css/styles.css">
{{ $title := print .Site.Title " | " .Title }} {{ $title := print .Title " | " .Site.Title }}
{{ if .IsHome }}{{ $title = .Site.Title }}{{ end }} {{ if .IsHome }}{{ $title = .Site.Title }}{{ end }}
<title>{{ $title }}</title> <title>{{ $title }}</title>
<script type="text/javascript" src="/js/bootstrap.min.js"></script> <script type="text/javascript" src="/js/bootstrap.min.js"></script>