Vladimir Kovalev
Vladimir Kovalev

Reputation: 31

How to get the message_id of received messages with Telethon?

I take replier.py as base code from official Telethon examples.
I want to get message id each time I receive a message.

...
@events.register(events.NewMessage)
async def handler(event):
    if not event.out:
        print(f'received message_id = {event.message_id()}')
    client = event.client

with client:
    client.add_event_handler(handler)
    client.run_until_disconnected()
>>> ... AttributeError: 'Message' object has no attribute 'message_id'

I've tried several variants with no success.
How to do it properly?

Upvotes: 2

Views: 7329

Answers (1)

Lonami
Lonami

Reputation: 7141

It's an attribute, and you use the dot operator to access it:

@events.register(events.NewMessage)
async def handler(event):
    message_id = event.id
    print(message_id)

See also Telethon's FAQ on that topic.

Upvotes: 6

Related Questions