简体   繁体   English

Telethon 使用 python 获取消息按钮

[英]Telethon get message buttons with python

Is there a way to get the URL or/and text of a button below the message?有没有办法获得 URL 或/和消息下方按钮的文本?

I'm using telethon with python.我正在使用带有 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.

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