S
S
sunekosuri2021-07-19 18:30:14
Python
sunekosuri, 2021-07-19 18:30:14

How to remove keyboard resend in aiogram?

I just started to study aiogram and faced with the fact that when I repeatedly enter the / start command, the keyboard is repeatedly sent (see screenshots).

60f59a184e18f274372574.png
60f59a52efe88103388297.png

The keyboard code is:

@dp.message_handler(commands=['start',])
async def send_start(message: types.Message):
  keyboard_markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
  bt1 = types.KeyboardButton(text = "Кнопка1")
  bt2 = types.KeyboardButton(text = "Кнопка2")
  keyboard_markup.add(bt1,bt2)
  await message.answer("Привет. Держи меню:",reply_markup=keyboard_markup)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
EgorSvinarev, 2021-07-20
@sunekosuri

Initialize the keyboard outside the command handler.

keyboard_markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
bt1 = types.KeyboardButton(text = "Кнопка1")
bt2 = types.KeyboardButton(text = "Кнопка2")
keyboard_markup.add(bt1,bt2)

@dp.message_handler(commands=['start',])
async def send_start(message: types.Message):
  await message.answer("Привет. Держи меню:",reply_markup=keyboard_markup)

M
Michael S., 2021-07-20
@BUUSSA

Well, firstly, remove the comma in Secondly, I’ll say in advance that row_width is 3 by default (change it to 2, otherwise it’s not beautiful). It seems like everything is even. If I were right now at the computer, I would check it again, but only the comma (above) annoys me and that's it.
commands=['start',]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question