Цикл for в aiogram

@dp.message_handler(state=Client.location)
async def location_data(message: types.Message, state: FSMContext):
    async with state.proxy() as data:
        data['location'] = message.text

    async with state.proxy() as data:
        age = data['age']
        location = data['location']
    
    filter_zaim = cur.execute(f'''SELECT * FROM zaims WHERE years="{age}" AND country="{location}";''')
    result = filter_zaim.fetchone()

    if result is not None:
        await message.answer(f'Вот список займов для {location} и {age} лет', reply_markup=kp)
        if data['age'] == '21-45':
            filter_zaim_years = cur.execute(f'''SELECT * FROM zaims WHERE country="{location}";''')
            filtered = filter_zaim_years.fetchall()

            for zaim in filtered:
                def zaims_buttons(data):
                    zaims_buttons_y = types.InlineKeyboardMarkup(resize_keyboard=True)
                    for i in data:
                        zaims_buttons_y.add(types.InlineKeyboardButton('ТУТ ТЕКСТ КНОПКИ', url=i[2]))
                    return zaims_buttons_y

                msg = f'{zaim[0]}{zaim[3]}'
                await bot.send_message(message.from_id, msg,
                                       reply_markup=zaims_buttons(filtered))
            await state.finish()

В общем, при выполнении кода:

for zaim in filtered:
 def zaims_buttons(data):
  zaims_buttons_y = types.InlineKeyboardMarkup(resize_keyboard=True)
   for i in data:
    zaims_buttons_y.add(types.InlineKeyboardButton('ТУТ ТЕКСТ КНОПКИ', url=i[2]))
    return zaims_buttons_y
    
   msg = f'{zaim[0]}{zaim[3]}'
   await bot.send_message(message.from_id, msg, reply_markup=zaims_buttons(filtered))
   await state.finish()

Сообщение выбивается с двумя кнопками, как сделать так, чтобы на каждое сообщение была своя кнопка, ссылки на кнопки находятся в бд


Ответы (1 шт):

Автор решения: skyhelper

Если зайти в мой профиль можно увидеть, что на все вопросы отвечаю сам.

В общем, нужно было просто убрать цикл for, огромное спасибо человеку под ником skyhelper за помощь.

→ Ссылка