Skip to content Skip to sidebar Skip to footer

Lamda Funtion In @bot.message_handler() Not Working Properly In Telebot Python

I tried to implement the following line of code in python script for a telegram bot building using telebot. @bot.message_handler(func=lambda msg:True if msg.text.startswith('/test'

Solution 1:

Because ternary operator has a specific syntax, that has to be followed:

<value if True> if <condition>else<value if False>

What you did in the first sample is:

<valueifTrue> if <condition>

Also you don't have to do it like you did

Trueif msg.text.startswith('/test') elseFalse

.startswith() returns bool on its own.

It's unclear what decorator does, but why don't you just perform the check inside of the function?

@bot.message_handlerdeftest_start(message):
    if msg.startswith('/test'):
        msg=bot.send_message(message.chat.id,'This is feature is under developement')

Post a Comment for "Lamda Funtion In @bot.message_handler() Not Working Properly In Telebot Python"