pytelegrambotapi - 无法访问 "from" 属性 因为它是关键字

pytelegrambotapi - can't access "from" property due to it being keyword

我正在尝试访问 message.reply_to_message.from 但在 VS Code 中它以黄色突出显示,我无法编译它。使用 ['from'] 时,它表示:

TypeError: 'Message' object is not subscriptable

如何访问“来自”?

message.reply_to_message.from.username

我阅读了标签并在 google 上找到了文档。 当您遇到此类问题时,请始终参考文档。 Here 列出了消息对象的所有属性。

在那里你可以阅读:

In Python from is a reserved word, use from_user instead.

From_user 来自文档如下:

Sender of the message; empty for messages sent to channels. For backward compatibility, this will contain a fake sender user in non-channel chats, if the message was sent on behalf of a chat.

尝试将替换为from_user