Telethon: cant print updates

Created on 11 Dec 2017  路  4Comments  路  Source: LonamiWebs/Telethon

i am trying to get updates and print it:

client = TelegramClient('session_name', api_id, api_hash, update_workers=1, spawn_read_thread=False)
client.connect()
from telethon.tl.types import UpdateShortMessage, PeerUser

def replier(update):
print(update.message[::-1])
if isinstance(update, UpdateShortMessage) and not update.out:
#client.send_message(PeerUser(update.user_id), update.message[::-1])
print(update.message[::-1])

client.add_update_handler(replier)
i send myself message from another account but nothing prints except -Press enter to stop this!

Most helpful comment

import telethon

TelegramClient = TelegramAPI('example',
                            api_id=12345,
                            api_hash='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                            update_workers=4,
                            spawn_read_thread=False)

def callback(update):
    print('I received', update)

TelegramClient.add_update_handler(callback)

TelegramClient._client.idle()

All 4 comments

spawn_read_thread=False

If that's false you need to call another method I can't see there.

@Lonami
i tryed this :
client.connect()
client = TelegramClient('session_name', api_id, api_hash, update_workers=1,spawn_read_thread=False)

from telethon.tl.types import UpdateShortMessage, PeerUser
def callback(update):
print('I received', update)

client = TelegramClient('session', api_id, api_hash,
update_workers=1, spawn_read_thread=False)

client.add_update_handler(callback)

nothing happens either

import telethon

TelegramClient = TelegramAPI('example',
                            api_id=12345,
                            api_hash='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                            update_workers=4,
                            spawn_read_thread=False)

def callback(update):
    print('I received', update)

TelegramClient.add_update_handler(callback)

TelegramClient._client.idle()

nothing happens either

The script probably terminates. @SyrianProgrammer's comment should work (thanks!), and you should have read the wiki @justxor.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

denilen picture denilen  路  3Comments

ksanderer picture ksanderer  路  3Comments

adv-zl picture adv-zl  路  3Comments

wdsjxh picture wdsjxh  路  3Comments

chri1389 picture chri1389  路  6Comments