eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.09k stars 2.03k forks source link

Incorrect message handling #1889

Closed LuckyArdhika closed 1 year ago

LuckyArdhika commented 1 year ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using? v4.9.0

  2. What OS are you using? Windows 10

  3. What version of python are you using? v3.10.6

Issue: The handler didnt handling correctly, when im texting 'adhewfg' or some random word, the bot return handler with specific text. My code looks like this:

@bot.message_handler(func=lambda message: "goBackProvider") # when i sent random word, the bot return message from this handler
def nextGuess(message):
    markup = types.ReplyKeyboardMarkup()
    btn1 = types.KeyboardButton(buyMLBB)
    btn2 = types.KeyboardButton(buyFF)
    btn3 = types.KeyboardButton(buyAOV)
    btn4 = types.KeyboardButton(buyPUBG)
    markup.add(btn1, btn2, btn3, btn4)
    bot.send_message(message.chat.id, "Silahkan memilih provider yang tersedia!", reply_markup=markup)

@bot.message_handler(func=lambda message: True) # my expectation is the bot return message from this handler
def what(message):
    bot.reply_to(message, 'Maaf, aku tidak mengerti maksud kamu, gunakan tombol/perintah untuk berinteraksi denganku')
did i forget something?
Badiboy commented 1 year ago

func=lambda message: "goBackProvider"

Lambda is wrong and always returns "True".

func=lambda mess: mess.text == "goBackProvider"