O
O
ovonel2021-03-11 13:40:49
Python
ovonel, 2021-03-11 13:40:49

Can't resolve AttributeError. Where did I go wrong?

I found a post on the link with the same problem as mine, but I'm slowing down and I can't figure out what's wrong. Code below. As I understand it, a lot could change in 3 years, but should it work anyway?

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
updater = Updater(token='токен') # Токен API к Telegram
dispatcher = updater.dispatcher

# Обработка команд

def startCommand(bot, update):
    bot.send_message(chat_id=update.message.chat_id, text='Привет, давай пообщаемся?')  
def textMessage(bot, update):
    response = 'Получил Ваше сообщение: ' + update.message.text
    bot.send_message(chat_id=update.message.chat_id, text=response)
    
# Хендлеры
    
start_command_handler = CommandHandler('start', startCommand)
text_message_handler = MessageHandler(Filters.text, textMessage)

# Добавляем хендлеры в диспетчер

dispatcher.add_handler(start_command_handler)
dispatcher.add_handler(text_message_handler)

# Начинаем поиск обновлений

updater.start_polling(clean=True)

# Останавливаем бота, если были нажаты Ctrl + C

updater.idle()


UPD: didn't write error
No error handlers are registered, logging exception.
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\telegram\ext\dispatcher.py", line 442, in process_update
handler.handle_update(update, self, check, context)
File "C:\ProgramData\Anaconda3\lib\site-packages\telegram\ext\handler.py", line 160, in handle_update
return self.callback(update, context)
File "untitled0.py", line 21, in startCommand
bot .send_message(chat_id=update.message.chat_id, text='Hi, let's chat?')
AttributeError: 'Update' object has no attribute 'send_message'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mkone112, 2021-03-11
@mkone112

No error -> no problem -> no solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question