Arguments for register_next_step_handler
Hello,
I want to be able to pass arguments to my callback function.
register_next_step_handler(message, callback, args*) ???
This would be very usefull, because a global dictionary with data is unnecessary then.
Thanks, Matthias
I think that support pass arguments would let next_step_handler to become too complicated. Now I don't have plan to support this feature.
@Mattze96 you can use lambdas as workaround:
bot.register_next_step_handler(msg, lambda m: callback(m, args*))
Ahh, thanks!
I will try that...
Am 28.09.2015 um 13:40 schrieb Timofey Urbanovich:
@Mattze96 you can use lambdas as workaround:
bot.register_next_step_handler(msg, lambda m: callback(m, args*))
Reply to this email directly or view it on GitHub: https://github.com/eternnoir/pyTelegramBotAPI/issues/72#issuecomment-143719642
Nice solution!
Is this solution works fine in your projects?
I have a problem with it: https://github.com/eternnoir/pyTelegramBotAPI/issues/395
Unfortunately, I can't refuse to use lamda :((( I really need to pass arguments to process_next_step, but sometimes message.text becomes None.
@stmotw, thanks a lot in half an hour and I began to cry, hugging my knees
Русским помогу тоже, правильно будет
code = bot.send_message(message.chat.id,'Введите потоки')
bot.register_next_step_handler(code, lambda m: threadd(code, text,))
в функции же def threadd(message,text):
Русским помогу тоже, правильно будет
code = bot.send_message(message.chat.id,'Введите потоки') bot.register_next_step_handler(code, lambda m: threadd(code, text,))в функции жеdef threadd(message,text):
Cпасибо, ахах как раз искал и нашел, можно ли без bot.reply_to делать)
Русским помогу тоже, правильно будет
code = bot.send_message(message.chat.id,'Введите потоки') bot.register_next_step_handler(code, lambda m: threadd(code, text,))в функции жеdef threadd(message,text):
Так не получилось, в функцию не передается сообщение введенное пользователем, вместо него в message передается сообщение из отправляющего метода.
Зато заработало так, оно и проще выглядит:
def first_poll(cu)
msg = bot.send_message(cu.cid, get_lang_phrase('how_much', cu.language))
bot.register_next_step_handler(msg, process_get_money, cu)
def process_get_money(message, cu)
m = message.text
if m.isdigit():
amount = float(m)
msg = bot.send_message(cu.cid, get_lang_phrase('how_long', cu.language))
bot.register_next_step_handler(msg, process_get_term, cu, amount)
def process_get_term(message, cu, amount)
m = message.text
if m.isdigit():
term = int(float(m))
ra = calculate_return_amount(amount, term)
send_calculated_results(cu, ra)
Русским помогу тоже, правильно будет
code = bot.send_message(message.chat.id,'Введите потоки') bot.register_next_step_handler(code, lambda m: threadd(code, text,))в функции жеdef threadd(message,text):Так не получилось, в функцию не передается сообщение введенное пользователем, вместо него в message передается сообщение из отправляющего метода.
Зато заработало так, оно и проще выглядит:
def first_poll(cu) msg = bot.send_message(cu.cid, get_lang_phrase('how_much', cu.language)) bot.register_next_step_handler(msg, process_get_money, cu) def process_get_money(message, cu) m = message.text if m.isdigit(): amount = float(m) msg = bot.send_message(cu.cid, get_lang_phrase('how_long', cu.language)) bot.register_next_step_handler(msg, process_get_term, cu, amount) def process_get_term(message, cu, amount) m = message.text if m.isdigit(): term = int(float(m)) ra = calculate_return_amount(amount, term) send_calculated_results(cu, ra)
Really. You are a genius!