AttributeError: 'str' object has no attribute 'message_handler'

exactly 'str' object.

import telebot  
bot = telebot.TeleBot = ('api') 
@bot.message_handler(content_types=['text'])
def get_text_messages(message):     
if message.text == "hello":   
    bot.send_message(message.from_user.id, "hello")
bot.polling(none_stop=True, interval=0)

what`s wrong?

I'm trying to create a telegram bot for the first time

Upvotes: 0

Views: 1610

Answers (1)

jeekiii
jeekiii

Reputation: 296

bot = telebot.TeleBot = ('api')

should be

bot = telebot.TeleBot('api')

The current version just makes telebot.Telebot to be equal to 'api', then bot to be equal to telebot.Telebot

As a result, bot equals 'api' which is a str, hence the error.

Upvotes: 1

Related Questions