0

I Have Created A CallBack Function In Python-Telegram-Bot Wrapper.

def add2(update: Updater, context: CallbackContext):
    query = update.callback_query  
    # add()
    query2 = link1
    _mirror(bot, update, query2)
    query.answer()

But I Am Getting AttributeError: 'NoneType' objcet Has No Attribute 'Message_id'

2022-04-12 06:37:46,195 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/telegram/ext/dispatcher.py", line 343, in process_update
    handler.handle_update(update, self, check, context)
  File "/usr/local/lib/python3.8/dist-packages/telegram/ext/handler.py", line 117, in handle_update
    return self.callback(update, context)
  File "/usr/src/app/bot/modules/mirror.py", line 266, in add2
    _mirror(bot, update, query2)
  File "/usr/src/app/bot/modules/mirror.py", line 228, in _mirror
    listener = MirrorListener(bot, update,isTar, tag, extract)
  File "/usr/src/app/bot/modules/mirror.py", line 39, in __init__
    super().__init__(bot, update)
  File "/usr/src/app/bot/helper/mirror_utils/status_utils/listeners.py", line 6, in __init__
    self.uid = self.message.message_id
AttributeError: 'NoneType' object has no attribute 'message_id'

Below Is The Link Of _mirror function: https://github.com/lzzy12/python-aria-mirror-bot/blob/master/bot/modules/mirror.py

Kenil
  • 19
  • 4
  • Your message object is None. Debug your code to figure out why you try to call a property on a None-type object. Most likely you should wrap the code that fetches it in a try-except clause and do something (like throw an error) when you can't fetch the message instead of trying to access it's properties before checking if it's not None. – BoboDarph Apr 12 '22 at 06:49
  • Does this answer your question? [Why do I get AttributeError: 'NoneType' object has no attribute 'something'?](https://stackoverflow.com/questions/8949252/why-do-i-get-attributeerror-nonetype-object-has-no-attribute-something) – Ture Pålsson Apr 12 '22 at 14:34

1 Answers1

0

the _mirror function passes the update to MirrorListener which apparently assumes that update.message is not None. but the add2 callback is apparently used as callback for a CallbackQueryHandler, since you access update.callback_query.

CallMeStag
  • 5,467
  • 1
  • 7
  • 22