如何从python电报帐户中读取最近的消息?

时间:2020-07-24 00:26:58

标签: telethon

我正尝试从电报帐户中读取最近的邮件,以使回复自动进行。

import configparser
from telethon.sync import TelegramClient, utils

config = configparser.ConfigParser()
config.read( "config.ini")

mySession = 'xyz'
myUserId = '@xyz'

async with TelegramClient(mySession, api_id, api_hash) as client:
    async for message in client.iter_messages(myUserId):
        print(message.sender_id, ':', message.text)

此代码要求提供凭据并成功登录我。.

Please enter your phone (or bot token): 9XXXXXXXXXXX
Please enter the code you received: 4XXXXX
Signed in successfully as SXXXXX

但是..

myself = client.get_me()
print( myself.stringify())

返回..

AttributeError                            Traceback (most recent call last)
<ipython-input-5-fddc5bc3f77b> in <module>
----> 1 print( myself.stringify())

AttributeError: 'coroutine' object has no attribute 'stringify'

请帮助。

0 个答案:

没有答案