简体   繁体   English

pytelegrambotapi - 由于它是关键字,因此无法访问“来自”属性

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

I'm trying to access message.reply_to_message.from but in VS Code it highlights in yellow, I can't compile it.我正在尝试访问message.reply_to_message.from但在 VS Code 中它以黄色突出显示,我无法编译它。 When using ['from'] it says this:当使用['from']时,它会这样说:

TypeError: 'Message' object is not subscriptable

How do I access "from"?如何访问“来自”?

message.reply_to_message.from.username

I read the tag and found the documentation on google.我阅读了标签并在谷歌上找到了文档。 When you having this kind of problems always refer to the doc.当您遇到此类问题时,请始终参考文档。 Here there are listed all the properties of the message object. 这里列出了消息 object 的所有属性。

There you can read:在那里你可以阅读:

In Python from is a reserved word, use from_user instead.在 Python 中 from 是保留字,请改用 from_user。

From_user from the doc is the following:文档中的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.为了向后兼容,如果消息是代表聊天发送的,这将在非频道聊天中包含虚假的发件人用户。

Try to replace user with from_user尝试用from_user替换用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM