我使用Telethon 1.19.1和Telethon文档中的示例代码,100%副本用于学习。 但是当我开始运行时,错误会弹出。 我尝试导入asyncio库,但无效。 你能帮我一下吗。 谢谢
这是我的代码
from telethon.sync import TelegramClient
api_id = xxxxxxx
api_hash = 'xxxxxxxxxxxxxxxxxxxxxxx'
client = TelegramClient('anon', api_id, api_hash)
async def main():
me = await client.get_me()
print(me.stringify())
username = me.username
print(username)
print(me.phone)
async for dialog in client.iter_dialogs():
print(dialog.name, 'has ID', dialog.id)
await client.send_message('me', 'Hello, myself!')
await client.send_message(-100123456, 'Hello, group!')
await client.send_message('+34600123123', 'Hello, friend!')
await client.send_message('username', 'Testing Telethon!')
message = await client.send_message(
'me',
'This message has **bold**, `code`, __italics__ and '
'a [nice website](https://example.com)!',
link_preview=False
)
print(message.raw_text)
await message.reply('Cool!')
await client.send_file('me', '/home/me/Pictures/holidays.jpg')
async for message in client.iter_messages('me'):
print(message.id, message.text)
if message.photo:
path = await message.download_media()
print('File saved to', path)
with client:
client.loop.run_until_complete(main())
目前没有回答
相关问题 更多 >
编程相关推荐