how to make a inline button generator with sqllite in aiogram 3.0

205 views Asked by At

I need to make a button generator using a database, here is an example on aiogram 2.0, how to do it on aiogram 3.0

def genmarkup(data):

builder = KeyboardBuilder(button_type=InlineKeyboardButton)
markup = InlineKeyboardMarkup(inline_keyboard=builder.export())


for i in data: 
    markup.add(InlineKeyboardButton(i[1], callback_data=i[2]))
return markup 
1

There are 1 answers

2
Marcin Orlowski On BEST ANSWER

You can try using the InlineKeyboardMarkup and InlineKeyboardButton classes:

from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, KeyboardBuilder

def genmarkup(data):
    builder = KeyboardBuilder()
    for i in data:
        button = InlineKeyboardButton(text=i[1], callback_data=i[2])
        builder.add(button)
    return builder.as_markup()