2

I´m trying to use the @bot.message_handler with lambda to capture some words in the messages sending in a group with my bot. I see a lot of examples and everybody use a code similar to this:

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

It runs, but if I send "hi" in the group (with the BOT inside), the BOT didn't say "I love you too!" and I don't why. But if I say /start, the BOT says "Welcome!!"

I tried with @bot.message_handler(func=lambda message: True) as I saw in https://github.com/eternnoir/pyTelegramBotAPI#a-simple-echo-bot but again it doesn't work.

What can I do to use message_handler and capture some words in the message?

Alberto Aguilera
  • 311
  • 1
  • 5
  • 13
  • Hi, I've just launched your code and didn't faced any problems. Please insert this line `telebot.logger.setLevel(__import__('logging').DEBUG)` right after `import telebot`, then try to communicate with your bot and share log your program would print. – mingaleg Dec 08 '18 at 17:20
  • When I say "hi" nothing hapend. When I try "/hi" it works. Only works when I write with / – Alberto Aguilera Dec 08 '18 at 17:29
  • How can I do to deactivate the debug mode? I delete the line "telebot.logger.setLevel(__import__('logging').DEBUG)" but it continue showing it. – Alberto Aguilera Dec 08 '18 at 20:36

1 Answers1

3

By default privacy mode is enabled for Telegram bots.

A bot running in privacy mode will not receive all messages that people send to the group. Instead, it will only receive:

Messages that start with a slash ‘/’ (see Commands above)

Replies to the bot's own messages

Service messages (people added or removed from the group, etc.)

Messages from channels where it's a member

You could disable privacy mode for your bot through BotFather.

Community
  • 1
  • 1
mingaleg
  • 2,017
  • 16
  • 28