Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'TeleBot' object has no attribute 'message_handler'

When I run the code below the following error message is displayed: 'TeleBot' object has no attribute 'message_handler'.

import telebot
from telebot import types
keyboard1 = telebot.types.ReplyKeyboardMarkup()
keyboard1.row('Ok', 'Bye')

bot = telebot.TeleBot('API')

@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Hi what do you want /start', reply_markup=keyboard1)
    
@bot.message_handler(content_types=['text'])
def send_text(message):
    if message.text.lower() =='Hello':
        bot.send_message(message.chat.id, message.text.upper() )
    elif message.text.lower() =='Bye':
        bot.send_message(message.chat.id,'see you soom' )
    elif message.text.lower() == 'I love you':
        bot.send_sticker(message.chat.id, 'API')

@bot.message_handler(content_types=['sticker'])
def sticker_id(message):
    print(message)

bot.polling(none_stop=True)
    

So what is wrong? I have installed pip and others. I wrote it on python IDLE. I wanted to make a telegram bot which gives stickers.

like image 941
Aruzhan Avatar asked Oct 24 '25 11:10

Aruzhan


2 Answers

Try this code:

pip3 uninstall telebot
pip3 uninstall PyTelegramBotAPI
pip3 install pyTelegramBotAPI
pip3 install --upgrade pyTelegramBotAPI
like image 60
MrSaLeH Avatar answered Oct 26 '25 00:10

MrSaLeH


I did

pip3 uninstall telebot

Then

pip3 uninstall PyTelegramBotAPI

And then

pip3 install PyTelegramBotAPI==2.2.3

And it works now!

PyTelegramBotAPI 3.0 have lot of changes and 3.0 API docs are not there yet. WIP. Use 2.2.3 older version instead and make sure you don't have any other bot api like telebot

like image 24
Sushang Agnihotri Avatar answered Oct 26 '25 00:10

Sushang Agnihotri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!