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

Viewed 3220

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 ?

1 Answers

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)
Related