Telegram bot (pyTelegramBotAPI) 不处理新用户加入群组

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

我最近使用 pyTelegramBotAPI (telebot) 创建了一个简单的电报机器人。 我添加了一个消息处理程序,它应该处理 每个 消息,包括新用户加入时出现在组中的消息,它们仍然是 Message 非空对象new_chat_members 属性.

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

即便如此,当我添加新用户时,机器人不会用 "I got the message" 字符串回复,尽管它确实捕获了其他消息。

为什么会这样?这是关于消息处理程序的问题吗?是否有更通用的处理程序可以确保捕获每次更新?

谢谢

您应该将“new_chat_members”指定为 content-types

这是一个欢迎新用户的示例工作片段:

import telebot
bot = telebot.TeleBot(TOKEN)

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

bot.polling()