简体   繁体   中英

Telegram bot (pyTelegramBotAPI) does not handle new user joining group

I have recently created a simple bot for telegram using the pyTelegramBotAPI (telebot). I added a message handler that is supposed to handle every message, including the ones that appear on a group when a new user joins, which are still Message objects a non-null new_chat_members property.

import telebot
bot = telebot.TeleBot(TOKEN)

[...]

@bot.message_handler(func=lambda m: True)
def foo(message):
    bot.send_message(message.chat.id,"I got the message")



bot.polling()

Even so, the bot does not reply with the "I got the message" string when I add a new user, although it does catch other messages.

Why is this happening? Is this a problem about the message handler? Is there maybe a more general handler that is sure to catch every update?

Thank you

you should specify " new_chat_members " as content-types .

Here is a sample working snippet that welcomes new users:

import telebot
bot = telebot.TeleBot(TOKEN)

@bot.message_handler(content_types=[
    "new_chat_members"
])
def foo(message):
    bot.reply_to(message, "welcome")

bot.polling()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM