仅通过用户名获取实体后,我可以通过 ID 获取实体。这是一个错误吗?来自 shell 的视频

I can get entity by ID after getting entity by username only. Is it a bug? Video from shell

我只能通过用户名获取实体后才能通过ID获取实体。这是一个错误吗?来自 shell

的视频

我正在使用 Mac 和 python 3

我正在尝试通过 ID 获取实体

entity = client.get_entity(1151511560)

但出现异常:

ValueError: Could not find the input entity for <telethon.tl.types.PeerUser object at 0x1172312e8>. Please read https://telethon.readthedocs.io/en/latest/extra/basic/entities.html to find out more details.

然后我通过用户名 "ekat01"

成功获取了一个实体

之后我通过id成功获取了实体

为什么我无法仅通过 ID 获取实体?我想,这是一个错误,不是吗?

带校样的视频 link:https://youtu.be/mnDNZZir5PY

Github -------------------------------------- --------

来自 juanvelascogomez:

如果我没记错的话,文档中有解释 "Users, chat and channel, Important section":https://telethon.readthedocs.io/en/stable/extra/basic/entities.html

一旦图书馆“看到”实体,您就可以使用它们的整数 ID。您不能使用图书馆未见过的 ID 中的实体。您必须让图书馆至少看到它们一次并正确断开连接。你知道实体在哪里,你必须告诉图书馆。它不会帮你猜的。

来自Lonami:

在干净的会话中,

with client:
    try:
        client.get_entity(1151511560)
    except ValueError:
        print('Error as expected')

    client.get_entity("ekat01")
    client.get_entity(1151511560)
    print('Works as expected')
prints:

错误符合预期 按预期工作 秒 运行,

with client:
    client.get_entity(1151511560)
    print('Works as expected')
prints:

按预期工作