python 3的全功能telegram客户端库
Telethon-aio的Python项目详细描述
⭐️ Thanks everyone who has starred the project, it means a lot!
telethon是一个asynciopython 3库 与Telegram的API交互。
如果您不喜欢asyncio,您仍然可以使用使用线程的a simpler version。
这是什么?
telegram是一种流行的消息传递应用程序。这个图书馆是指 使编写能够交互的python程序变得容易 用电报。把它想象成一个已经完成了 你的工作很繁重,所以你可以专注于开发应用程序。
安装
pip3 install telethon-aio
创建客户机
importasyncioloop=asyncio.get_event_loop()fromtelethonimportTelegramClient# These example values won't work. You must get your own api_id and# api_hash from https://my.telegram.org, under API Development.api_id=12345api_hash='0123456789abcdef0123456789abcdef'client=TelegramClient('session_name',api_id,api_hash)loop.run_until_complete(client.start())
做事
asyncdefmain():me=awaitclient.get_me()print(me.stringify())awaitclient.send_message('username','Hello! Talking to you from Telethon')awaitclient.send_file('username','/home/myself/Pictures/holidays.jpg')awaitclient.download_profile_photo('me')messages=awaitclient.get_messages('username')awaitmessages[0].download_media()loop.run_until_complete(main())
下一步
你喜欢Telethon的样子吗?查看Read The Docs获得更深入的解释, 提供示例、疑难解答和更多有用信息。