pythonforexpyalgotrade

Python telegram bot with pyrogram stopped receiving messages from some channels


My telegram bot built using python and pyrogram was working properly i.e. receiving all the messages from all telegram subscribed channels. It started having the following problems:

  1. Not receiving messages from telegram channels
  2. Not receiving all the messages received on the telegram channels
from pyrogram import Client, filters

TELEGRAM_API_ID = xxxxx
TELEGRAM_API_HASH = "xxxxx"
TELEGRAM_BOT_TOKEN = "xxxxx" 
TELEGRAM_BOT_NAME="xxxxx"
bot = Client(TELEGRAM_BOT_NAME, api_id=TELEGRAM_API_ID, api_hash=TELEGRAM_API_HASH)

bot.on_message(filters.channel)
async def telegram_bot_main(client, message):
   print(message.text)
bot.run()

I expect to :

  1. To receive all the messages from all subscribed channels

Solution

  • Did you miss something @ from the decorator.

    @bot.on_message(filters.channel)
    async def telegram_bot_main(client, message):
       print(message.text)
    

    Addition to the answer:
    I also encountered a similar problem when the client suddenly stopped receiving updates from the channel I was interested in.

    From participating in an exciting program, I received the following comments:
    "Chats fell off on average from 1k users, groups from 100k. Now people are looking for the cause of the error, but this is open source, as they will find it fixed.".

    Pay attention to these warnings:

    # Pyrogram is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Lesser General Public License for more details.
    

    You can "manually" receive updates, to do this, you need to use the

    TELEGRAM RAW API :

    Raw Functions
    Raw Types
    Raw Base

    Or start working with TDLib
    An example of TDLib in Python
    Python Wrapper TDLib