V
V
violpeople2021-07-08 00:07:36
Python
violpeople, 2021-07-08 00:07:36

How to fix a bug?

Hello!
I would like to know why such a bug occurs (or just why it happens and how to fix it). I am using aiogram

I have a split calldata in a function that is bound to an "Add to Cart" button

@dp.callback_query_handler(lambda c: c.data.startswith('add_'))
async def add_to_cart(call: types.CallbackQuery):
    operation = call.data.split('_')[0]
    current_item = int(call.data.split('_')[-1])
    
    item = items[current_item]
    print(operation, current_item, item, prices)

60e61b9f51f47710548112.png
(I made a print to see what is happening in the console, and it is clear that when you click on the "next" button, the bot goes to product 2, but when you click on the "add" button, it adds product number 3)

There is also a list from which the bot takes information
items = [
    'Атомик 60|70|80 см',#0
    'Болевар 60|70|80 см',#1
    'Вайт  О"Хара 40|60 см',

So the question is - why when I click on this button, then the next product is added to me?
For example, the bot is located on "Bolevar", but adds "White O" hara"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-07-08
@violpeople

violpeople , gotta

add = InlineKeyboardButton(text= 'Добавить в корзину',callback_data= f'add_{current_item}')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question