Telegram get chat messages /posts - python Telethon

后端 未结 3 2105
-上瘾入骨i
-上瘾入骨i 2021-01-11 13:08

I am using Telethon and Python 3.6xx

Been able to retreive message from groups, no problem but when it comes to channels I am stuck.

dialogs = clien         


        
3条回答
  •  萌比男神i
    2021-01-11 13:36

    update :

    in the new version of Telethon, @Lonami answer is best and use it.

    ############################################################

    you can use this code for get messages :

    client = TelegramClient('session_name',
                        api_id,
                        api_hash,
                        update_workers=1,
                        spawn_read_thread=False)
    assert client.connect()
    if not client.is_user_authorized():
        client.send_code_request(phone_number)
        me = client.sign_in(phone_number, input('Enter code: '))
    
    channel_username='tehrandb' # your channel
    channel_entity=client.get_entity(channel_username)
    posts = client(GetHistoryRequest(
        peer=channel_entity,
        limit=100,
        offset_date=None,
        offset_id=0,
        max_id=0,
        min_id=0,
        add_offset=0,
        hash=0))
    # messages stored in `posts.messages`
    

提交回复
热议问题