eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.12k stars 2.03k forks source link

AsyncTeleBot doesn't get updates for service messages in Telegram #1950

Closed Al-Sharabi closed 1 year ago

Al-Sharabi commented 1 year ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using? 4.10.0
  2. What OS are you using? Windows
  3. What version of python are you using? Python 3.10.9

For some reason, AsyncTeleBot doesn't get updates from service messages. For example, I have a bot in a group. If I run this code and then I pin a message I get no result.

bot = AsyncTeleBot(BOT_TOKEN)

async def func_that_triggers_when_pinned(mess):
    print(mess)

bot.register_message_handler(func=(lambda x: True if x.pinned_message else False), callback=func_that_triggers_when_pinned)

import asyncio
asyncio.run(bot.polling())

Even if I just let func be True all the time, I get no update when the message is a service message i.e. someone joined the chat, someone left the chat, pinned message etc. If I run this, however, it works.

bot = telebot.TeleBot(BOT_TOKEN)

def func_that_triggers_when_pinned(mess):
    print(mess)

bot.register_message_handler(func=(lambda x: True if x.pinned_message else False), callback=func_that_triggers_when_pinned)

bot.polling()

I have even tried polling(allowed_updates=telebot.util.content_type_service) but it didnt work

Badiboy commented 1 year ago

https://github.com/eternnoir/pyTelegramBotAPI#message-handlers

See about content_types here.