2

@bot.message_handler をラムダで使用して、ボットを使用してグループで送信するメッセージの単語をキャプチャしようとしています。多くの例を見て、誰もが次のようなコードを使用しています。

import telebot

telebot.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()

実行されますが、グループ内 (BOT が入っている状態) で "hi" を送信すると、BOT は "I love you too!" とは言いませんでした。理由はわかりません。しかし、/start と言うと、BOT は「ようこそ!!」と言います。

https://github.com/eternnoir/pyTelegramBotAPI#a-simple-echo-botで見たように @bot.message_handler(func=lambda message: True) で試しましたが、やはり機能しません。

message_handler を使用してメッセージ内の単語をキャプチャするにはどうすればよいですか?

4

1 に答える 1