Ask Your Question
3

What is the method to obtain the most recent event in the admin log of a Telegram Telethon channel?

asked 2022-08-17 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-08-10 16:00:00 +0000

plato gravatar image

To obtain the most recent event in the admin log of a Telegram Telethon channel using the Telethon library in Python, you can use the get_admin_log method. Here is an example code snippet:

from telethon import TelegramClient, events, sync

# Replace the values with your own API ID, API HASH, and phone number
api_id = YOUR_API_ID
api_hash = 'YOUR_API_HASH'
phone = 'YOUR_PHONE_NUMBER'

with TelegramClient('session_name', api_id, api_hash) as client:
    client.start(phone)

    # Replace CHANNEL_USERNAME with the username of the channel
    channel = client.get_entity('CHANNEL_USERNAME')

    # Get the most recent event in the admin log
    log = client(GetAdminLogRequest(channel, 0, 0, 1, 0))
    event = log.events[0]

    print(event.stringify())

This code first creates a TelegramClient object and starts a session with the provided phone number. It then gets the Entity object for the channel using its username.

The GetAdminLogRequest method is used to retrieve the admin log of the channel. The 0 values in the method call are used for the parameters min_id, max_id, and limit, respectively. The 1 parameter for types specifies that only the most recent event should be returned. The 0 parameter for q specifies that no filter is applied.

The result of the GetAdminLogRequest is stored in the log variable. The most recent event is then accessed by indexing into the events property of the log, and printed using the stringify() method.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-17 11:00:00 +0000

Seen: 9 times

Last updated: Aug 10 '22