Rea
Rea

Reputation: 135

How to solve this error : AttributeError: 'NoneType' object has no attribute 'reply_text'?

I've a button , it's supposed to return the ask_wikipedia function , so I used CallbackQueryHandler but when i want to call ask_wikipedia function i recive an attribute error ! Why? How can i fix it ?

def Click_Button(update, context) :
    query = update.callback_query
    if query.data == "Research":
        ask_wikipedia(update, context)

query_handler = CallbackQueryHandler(Click_Button)

dispatcher.add_handler(query_handler)



def ask_wikipedia(update, context)  :
    update.message.reply_text('What do you want to know about ? πŸ”Ž')
    return About


When I click on the button I get this error

AttributeError: 'NoneType' object has no attribute 'reply_text'

How can I fix it ?

Upvotes: 5

Views: 7595

Answers (2)

Faced AttributeError: 'NoneType' object has no attribute 'reply_text' error in my app. After investigation found that it raises when user edit original message, so in update I get edited_message instead of message. So I decided to use update.effective_chat.send_message instead of update.message.reply_text to avoid this problem. Even if it not solution for you, keep in mind that it might be edited_message in update instead of message.
(Wrote here because it is first in google for this Error)

Upvotes: 1

Beppe C
Beppe C

Reputation: 13943

When replying to a text message (from a MessageHandler) is fine to use update.message.reply_text, but in your case the incoming message is a managed by the CallbackHandler which receives a different object.
You can reply using

update.callback_query.message.edit_text(message)

Upvotes: 6

Related Questions