相关疑难解决方法(0)

Telethon 导致“RuntimeWarning:协程‘MessageMethods.send_message’从未等待过”

我正在尝试运行Telethon 文档提供的第一个代码片段。但是,在出现多个问题(此处此处)之后,我最终得到了这个修改后的版本:

import os
import sys
from telethon.sync import TelegramClient, events

# import nest_asyncio
# nest_asyncio.apply()

session_name = "<session_name>"
api_id = <api_id>
api_hash = "<api_hash>"


os.chdir(sys.path[0])

if f"{session_name}.session" in os.listdir():
    os.remove(f"{session_name}.session")

async with TelegramClient(session_name, api_id, api_hash) as client:
   client.send_message('me', 'Hello, myself!')
   print(client.download_profile_photo('me'))

   @client.on(events.NewMessage(pattern='(?i).*Hello'))
   async def handler(event):
      await event.reply('Hey!')

   client.run_until_disconnected()
Run Code Online (Sandbox Code Playgroud)

但是现在我收到这些警告:

usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:23:RuntimeWarning:协程“MessageMethods.send_message”从未等待
RuntimeWarning:启用tracemalloc以获取对象分配回溯
/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:24:RuntimeWarning:从未等待协程“DownloadMethods.download_profile_photo”
RuntimeWarning:启用tracemalloc以获取对象分配回溯
/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:30:RuntimeWarning:从未等待协程“UpdateMethods._run_until_disconnected”
RuntimeWarning:启用tracemalloc以获取对象分配回溯

在 Jupyter 上运行代码时。现在我的问题是:

  • 这些警告消息意味着什么以及我应该如何解决它们?
  • 如果正常工作,这段代码的预期结果是什么?我应该通过 Telegram 或其他方式收到消息吗?因为除了登录码之外我没有收到任何消息。
  • @行首的符号是什么@client.on...意思?那条线应该做什么?从这一行开始我就不明白代码了。如果您能帮助我理解它,我将不胜感激。

python ipython python-asyncio telegram telethon

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

ipython ×1

python ×1

python-asyncio ×1

telegram ×1

telethon ×1