Answer the question
In order to leave comments, you need to log in
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).
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
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)
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 questionAsk a Question
731 491 924 answers to any question