Home>

Hello everyone, I'm writing a bot in python. I connected the telegram.ext library, but for some reason the functions do not see the bot argument, but at the same time update sees if the context is passed instead of the bot passing the context. Because of this, I can not get the data on the back , should return a dictionary, but in fact there is nothing to return except the passed context.

Error log in line 20, in talk_to_me user_text= "Message {}! wrote {}". format (update.message.chat.first_name, update.message.text) AttributeError: 'CallbackContext' object has no attribute 'message'

don't see the use of the bot variable

ganz2021-11-04 16:16:54

I don’t use it yet, but update doesn’t seem to work, or it doesn’t work that way

sergey2021-11-04 16:22:29

you know that update must be called three times, that is, the message and chat functions must return callable objects ... well, here you are too clever ... simple is better than complex

ganz2021-11-04 16:33:55

thanks a lot

sergey2021-11-04 16:37:35

sure everything is clear?

ganz2021-11-04 16:43:08
  • Answer # 1

    either we do not call, but have a nesting of the dictionary three and the message chat variables must be declared, that is

    # the function will return an empty list with which you can do whatever you want
             return []
    a (). append (1)
    print (a ()) # will print an empty list since the function was called NEW time
    you're trying to do something like
    def b ():
         return [[], ['x']]
    b () [1] [0]
    

    that is, to access the object, which must return another object (namely, return and not have a way of calling) the same is true for classes. As I said earlier, triple access is terrible -it's hard to understand. it is better to use variables, albeit unnecessary that is, something like this:

    c= b ()
    # [[], ['x']]
    cc= c [1]
    ccc= cc [0]
    

    at least during development [added] answered here because the comments are not convenient

    Roughly understood, thanks, I'll try

    sergey2021-11-04 17:08:08