Python Forum

Full Version: How to conditionally execute correctly?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
@bot.message_handler(commands=['start'])
def get_filial(message: types.Message):
    
    markup_inline_filial=types.InlineKeyboardMarkup()
    item_shop1=types.InlineKeyboardButton(text='Shop1', callback_data='shop1')
    item_shop2=types.InlineKeyboardButton(text='Shop2', callback_data='shop2')
    markup_inline_filial.add(item_shop1,item_shop2)

@bot.callback_query_handler(func=lambda call:call.data=='shop1')
def get_select_button_shop1(call: types.CallbackQuery):
    markup_inline_item=types.InlineKeyboardMarkup()
    markup_inline_item.add()
    bot.edit_message_text(chat_id=call.message.chat.id,message_id=call.message.id,text="Choose one:",reply_markup=markup_inline_item)

@bot.message_handler()
def message_handler_shop1(message):
    if message.text in ['1','2','3','4']:
        send_docs_shop1(message)
    else:
        send_query_shop1(message)

def send_docs_shop1(message):
    file_source=open(f"E:\shop1_{message.text}.csv")
    bot.send_document(message.chat.id, file_source) 
 
def send_query_shop1(message):
    bot.send_document(message.chat.id, "Hello from shop1")
 
@bot.callback_query_handler(func=lambda call:call.data=='shop2')
def get_select_button_shop2(call: types.CallbackQuery):
    markup_inline_item=types.InlineKeyboardMarkup()
    markup_inline_item.add()
    bot.edit_message_text(chat_id=call.message.chat.id,message_id=call.message.id,text="Choose one:",reply_markup=markup_inline_item)

@bot.message_handler()
def message_handler_shop2(message):
    if message.text =='o':
        send_docs_shop2(message)
    else:
        send_query_shop2(message)
    
def send_docs_shop2(message):
    file_source=open(f"E:\shop2_{message.text}.csv")
    bot.send_document(message.chat.id, file_source) 
 
def send_query_shop2(message):
    bot.send_document(message.chat.id, "Hello from shop2")
There's code there and no real question. It would help if you told us what problem you're having, any errors, etc.
Sorry, I need that when "Shop1" is selected, the code for "shop1" is executed, and when "Shop2" is selected, the code for "shop2" is executed.

Currently both "Shop1" and "Shop2" execute "Shop1".
So how have you debugged the program to work out why it isn't working correctly?
(Nov-12-2022, 08:15 AM)lolita7777 Wrote: [ -> ]Sorry, I need that when "Shop1" is selected, the code for "shop1" is executed, and when "Shop2" is selected, the code for "shop2" is executed.

Currently both "Shop1" and "Shop2" execute "Shop1".

sorry, beginner coder, so I don't know a lot of things yet
help me please