Answer the question
In order to leave comments, you need to log in
How to pass a list of buttons in the aiogram library to the add function?
@dp.message_handler( filters.CommandStart() )
async def start( message: types.Message ):
await message.answer(
'hi',
reply_markup =
InlineKeyboardMarkup(row_width=1).add(
[InlineKeyboardButton(text = "Apples", callback_data='1'),
InlineKeyboardButton(text = "Oranges", callback_data='2'),
InlineKeyboardButton(text = "Beans", callback_data='3')]
)
)
Answer the question
In order to leave comments, you need to log in
You need to unpack your list, or simply pass it there separated by commas.
@dp.message_handler( filters.CommandStart() )
async def start( message: types.Message ):
await message.answer(
'hi',
reply_markup =
InlineKeyboardMarkup(row_width=1).add(
*[InlineKeyboardButton(text = "Apples", callback_='1'),
InlineKeyboardButton(text = "Oranges", callback_data='2'),
InlineKeyboardButton(text = "Beans", callback_data='3')]
)
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question