E
E
euiwn2021-03-24 02:56:31
Python
euiwn, 2021-03-24 02:56:31

Telebot, how to pass a function with two parameters to callback?

First, I create a function with which I form a list, after which I return this list. Then I process it, compose a bot message, add a keyboard. Now I need the same list generated in the first function to come to the user by clicking on the button.

def list_creation(message): #тут у меня message, т.к. список формируется в зависимости от сообщения пользователя.
    My_List= str('\n'.join(My_List))
    return My_List

def list_message(message, My_List):
    if My_List:  #проверка на пустоту списка
       bot.send_message(message.chat.id, My_List) 
    else:
        bot.send_message(message.chat.id, 'Список пуст!') 

def button(message):
    markup = types.InlineKeyboardMarkup()
    button = types.InlineKeyboardButton(text="Get_List", callback_data="list")
    markup.add(button)
    bot.send_message(chat_id=message.chat.id, text="Какой cписок Вас интересует?", reply_markup=markup)

@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call, My_List):  
    if call.data == "list":
          list_message(call.message, My_List)     # Вот тут у меня и началась проблема.
Ошибка следующая:
TypeError: callback_inline() missing 1 required positional argument: 'My_List'


Please tell me how to solve my problem? Are there alternative options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-03-24
@euiwn

The only option is to push the list itself into callback_data when creating the button. For example, as a JSON string. But there are restrictions on the size, up to 64 bytes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question