【问题标题】:On message event from telethon returns from_id None来自 telethon 的消息事件返回 from_id None
【发布时间】:2022-12-12 21:14:46
【问题描述】:

尝试从其中只有媒体(照片、文档、语音、视频)的消息访问 from_id 属性时出现错误。错误:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\updates.py", line 467, in _dispatch_update
    await callback(event)
  File "d:\Code\asd\back.py", line 16, in on_message
    await pl.add_message(f'saved/{event.peer_id.user_id}/chat.json', event)
  File "d:\Code\asd\plugins.py", line 25, in add_message
    'author': event.from_id.user_id if event.from_id.user_id != None else event.peer_id.user_id,
AttributeError: 'NoneType' object has no attribute 'user_id'

发送媒体时不会出现错误,只有当我将媒体发送给我时才会发生。 我希望你们中的一些人可以帮助我找到问题的答案。

我一直在尝试使用 peer_id 而不是 from_id,但这并没有帮助

【问题讨论】:

  • 请显示您的代码

标签: telegram telethon


【解决方案1】:

自引入 Anonymous Admins 以来,Telegram 聊天中的消息可以没有发件人。

在 Telethon 中,您应该使用 message.sender_id 而不是 from_id

参考:https://t.me/TelethonChat/126622

【讨论】:

    猜你喜欢
    • 2021-05-25
    • 1970-01-01
    • 2021-08-20
    • 2022-01-17
    • 1970-01-01
    • 2022-08-02
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    相关资源
    最近更新 更多