R
R
Ribachok2022-04-21 20:17:28
Python
Ribachok, 2022-04-21 20:17:28

How to get the id of a post in the channel chat?

The post ID in the channel and the channel chat are different. How to get channel message id in telethon chat?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sanders rocket, 2022-04-22
@rocketmachine

next_post = cli.iter_messages(
                entity,
                limit=5,
                min_id=your_post_id,
                reverse=True
            )

P
PtrGrd, 2022-04-24
@PtrGrd

I will show the implementation using the example of Pyrogram:

from pyrogram import Client

with Client(session_name="имя .session", api_id="твой api_id", api_hash="api_hash соответственно") as client:
    data_channel = client.get_chat("название чата/канала") # получаешь всю информацию о канале с подключенным чатом
    chat = data_channel.linked_chat.id # получаешь id чата
    
    for message in client.iter_history(chat, limit=100): # поставь любой лимит
        post_id = message['message']
        print(post_id) # все данные о сообщении, в том числе его id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question