C
C
CookieMonster322020-05-22 09:41:08
Python
CookieMonster32, 2020-05-22 09:41:08

How to fix AttributeError: 'KeyboardButtonUrl' object has no attribute 'data' error in telethon?

Hi all! I am writing a small program using telethon. I've read the manuals but haven't found anything. Here is the required code:

button_data = msg.reply_markup.rows[0].buttons[0].data

Mistake:
button_data = msg.reply_markup.rows[0].buttons[0].data
AttributeError: 'KeyboardButtonUrl' object has no attribute 'data'


And yes, "data" is the last word in the series.
Here is the whole code:
from telethon.sync import TelegramClient


api_id = ''
api_hash = ''
client = TelegramClient('', api_id, api_hash)
client.start()
dlgs = client.get_dialogs()
for dlg in dlgs:
  print(dlg.title)
for dlg in dlgs:
  if dlg.title == '':
    tegmo = dlg
msgs = client.get_messages(tegmo, limit=30)
for msg in msgs:
  if msg.reply_markup is not None:
    button_data = msg.reply_markup.rows[0].buttons[0].data
    message_id = msg.id          
    print(button_data, msg.id)#
from telethon.tl.functions.messages import GetBotCallbackAnswerRequest

resp = client(GetBotCallbackAnswerRequest(
  tegmo,
  message_id,
  data=button_data
  ))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question