Search code examples
telethon

Reactions to messages Telegram/Telethon


The "telethon" library has a "get messages" method, with which you can get a message and information about it, including comments.

But can you get reactions? https://core.telegram.org/method/messages.getMessageReactionsList


Solution

  • I couldn't find a way to do this via telethon. However, you can get a list of reactions to messages using pyrogram: GetMessageReactionsList

    Something like that:

    from pyrogram import Client
    from pyrogram.raw.functions.messages import GetMessageReactionsList
    
    
    app = Client(
        "my_account",
        api_id=12345678,
        api_hash='XXX'
    )
    
    chat_id = -123456789
    
    with app:
        peer = app.resolve_peer(chat_id)
    
        for message in app.iter_history(chat_id=chat_id):
            reactions = app.send(
                GetMessageReactionsList(
                    peer=peer,
                    id=message.message_id,
                    limit=100
                )
            )
    

    UPD Found an easier way:

    with app:
        peer = app.resolve_peer(chat_id)
    
        for message in app.iter_history(chat_id=chat_id):
            print(message.reactions)