Answer the question
In order to leave comments, you need to log in
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'
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question