Answer the question
In order to leave comments, you need to log in
How to fix "AttributeError: 'KeyboardButton' object has no attribute 'data' PYTHON" error?
Mistake:
button_data = msg.reply_markup.rows[0].buttons[0].data
AttributeError: 'KeyboardButton' object has no attribute 'data'
from telethon import TelegramClient, sync, events
api_id =
api_hash = ''
client = TelegramClient('boters', api_id, api_hash)
client.start()
dlgs = client.get_dialogs()
for dlg in dlgs:
print(dlg.title)
for dlg in dlgs:
if dlg.title == '':
client.send_message('', "")
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, message_id)
from telethon.tl.functions.messages import GetBotCallbackAnswerRequest
resp = client(GetBotCallbackAnswerRequest(
tegmo,
58462,
data=b'hatgiong;7187'
))
print(resp.message)
Answer the question
In order to leave comments, you need to log in
There is no such button! Means write down between try except. If it doesn't, nothing will happen, if it does, then it will click.
Or do it print(msg.reply_markup.rows)
and see what's there.
Here are some more similar questions:
* How to fix AttributeError: 'KeyboardButtonUrl' object has no attribute 'data' error in telethon?
* python - AttributeError: 'KeyboardButtonUrl' objec...
* Question: How would I interact with a bot's button...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question