D
D
D55RUS2020-04-25 20:21:21
Python
D55RUS, 2020-04-25 20:21:21

How to transfer a variable from one function to another telebot?

Basically, I have this code:

bot.send_message(message.chat.id, 'Скажи свою фамилию')
bot.register_next_step_handler(message, last_name)

def last_name(message):
   last_name = message.text
   bot.send_message(message.chat.id, 'Скажи свое имя')
   bot.register_next_step_handler(message, first_name)

def first_name(message):
   firstName = message.text
   bot.send_message(message.chat.id, f'{last_name} + f'{firtsName} + 'я вас запомнил')


Throws an error. Tried through a global variable, but it also throws an error because: last_name = message.text.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2020-04-25
@D55RUS

in register_next_step_handler the first 2 parameters are the message and the function to be called. Next, parameters are passed if the called function has any parameters other than message.
bot.register_next_step_handler(message, first_name, < Parameter1 >, < Parameter2 >)
...
def first_name(message, < Parameter1 >, < Parameter2 >):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question