[英]Telethon get message buttons with python
You can access the buttons of a message using its message.buttons
property.您可以使用消息的
message.buttons
属性访问消息的按钮。 This property returns a list, each element of list is a row(list) of MessageButton .此属性返回一个列表,列表的每个元素都是MessageButton的一行(列表)。
For example, if you want to access the URL or text of send music to friends button which is in row 1 and column 0 ( 0 based index ), you can use the following code:例如,如果您想访问 URL 或第 1 行第 0 列(基于 0 的索引)中的向朋友发送音乐按钮的文本,您可以使用以下代码:
peer_username = "Telegram identifier"
message = client.get_messages(peer_username)[0]
message_button = message.buttons[1][0]
text = message_button.text
url = message_button.url
Sometimes the url
property in the MessageButton is empty, and you can use its button
property to access the KeyboardButton .有时 MessageButton 中的
url
属性为空,您可以使用其button
属性访问KeyboardButton 。 For example:例如:
url = message_button.button.url
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.