我正在尝试使用带有 lambda 的 @bot.message_handler 来捕获与我的机器人一起发送的消息中的一些单词。我看到很多例子,每个人都使用类似的代码:import telebottelebot.logger.setLevel(__import__('logging').DEBUG)bot_token = 'Blablabla'bot = telebot.TeleBot(bot_token)# filter on a specific message@bot.message_handler(func=lambda message: message.text == "hi")def command_text_hi(m): bot.send_message(m.chat.id, "I love you too!")@bot.message_handler(commands=['start'])def send_welcome(m): bot.send_message(m.chat.id, 'Welcome!')@bot.message_handler(func=lambda message: True, content_types=['text'])def command_default(m): # this is the standard reply to a normal message bot.send_message(m.chat.id, "I don't understand, try with /help")bot.polling()它运行,但是如果我在组中发送“hi”(里面有 BOT),BOT 不会说“我也爱你!” 我不知道为什么。但是如果我说 /start,BOT 会说“欢迎!!”正如我在https://github.com/eternnoir/pyTelegramBotAPI#a-simple-echo-bot 中看到的那样,我尝试使用 @bot.message_handler(func=lambda message: True)但它再次不起作用。如何使用 message_handler 并捕获消息中的一些单词?
1 回答

慕码人8056858
TA贡献1803条经验 获得超6个赞
添加回答
举报
0/150
提交
取消