使用telethon包的时候,上传文件到tg机器人,遇到以下报错
TypeError: An asyncio.Future, a coroutine or an awaitable is required
实际使用:
from telethon import TelegramClient
client = TelegramClient(name, api_id, api_hash)
def sendFileMsg():
client.send_file("+852xxxxxxx", 'test.txt', voice_note=True)
with client:
client.loop.run_until_complete(sendFileMsg())
这个报错实际看文档能大概知道是什么原因,文档里示范client的使用:
from telethon import TelegramClient
client = TelegramClient(name, api_id, api_hash)
async def main():
# Now you can use all client methods listed below, like for example...
await client.send_message('me', 'Hello to myself!')
with client:
client.loop.run_until_complete(main())
client.loop.run_until_complete直接调用的时候,方法需要异步,即修改为:
async def sendFileMsg():
client.send_file("+852xxxxxxx", 'test.txt', voice_note=True)