最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to use pyrogram without subscribing to the channel? - Stack Overflow

programmeradmin3浏览0评论

I have a telegram bot and a client. The telegram bot is added to all the channels I need (as an administrator). Since bots do not have access to the message history, I receive messages using the client. But I want to make it so that it is not necessary to add it to the channel. How can I do this, and is it even possible? (Channels are public).

My code using pyrogram (but here you need to add the client to the channel):

from pyrogram import Client, utils

from config import API_ID, API_HASH, PHONE_NUMBER, CHANNEL_ID

api_id = API_ID
api_hash = API_HASH

app = Client('client', api_id=api_id, api_hash=api_hash, phone_number=PHONE_NUMBER)


with app:
    messages = app.get_chat_history(chat_id=CHANNEL_ID, limit=15)
    for message in reversed(list(messages)):
        print('Text:', message.text or message.caption)
        print('Views:', message.views)
        print('Date:', message.date)

If I don't subscribe to the channel and execute this code, there will be an error:

pyrogram.errors.exceptions.not_acceptable_406.ChannelPrivate: Telegram says: [406 CHANNEL_PRIVATE] (caused by "messages.GetHistory") Pyrogram 2.2.4 thinks: You haven't joined this channel/supergroup.

If I use BOT_TOKEN for authorization, there will be an error:

pyrogram.errors.exceptions.bad_request_400.BotMethodInvalid: Telegram says: [400 BOT_METHOD_INVALID] (caused by "messages.GetHistory") Pyrogram 2.2.4 thinks: The method can't be used by bots
发布评论

评论列表(0)

  1. 暂无评论