android - pyTelegramBotAPI func filter and commands filter message_handler -
my intention develop bot pytelegrambotapi, in internal state 'state' allows or disallows access commands.
the expected output in fragment message if command 'plan' , 'state' 0
my code:
import telebot
token = 'token'
tb = telebot.telebot(token)
state = 0
@tb.message_handler(commands=['plan'], func=lambda state: state == 0)
def planfunct(m):
idcon = m.chat.id tb.send_message(idcon, 'el comando plan funciona.' + str(idcon)) tb.polling(none_stop=true)
the result of fragment no way out. , not able recognize if problem starts bad use of filters, scope of variables, or misuse of lambda function.
i appreciate help, first question in stack overflow.
regards
a possible solution problem, use common function through def, problem lies in difficulty pass parameter function when applying syntax of filter 'func'.
to use parameter, assign value inside function, because has scope obtain it.
my code:
import telebot token = 'token' tb = telebot.telebot(token) satate = 0 def comprobarestados(m): m = state if m == 0: return true @tb.message_handler(commands=['plan'], func=comprobarestados) def planfunct(m): idcon = m.chat.id tb.send_message(idcon, "el comando plan funciona.") tb.polling(none_stop=true)
Comments
Post a Comment