Forums

Problems with using PyTelegramBotAPI

I`m trying to make a simple telegram bot, but I have a problem. I've installed all necessary modules using bash as you can see, but I got AttributeError: 'TeleBot' object has no attribute 'message_handler' and if I use sys.modules() while running main file - there is no pytelegrambotapi module. How can I fix it?

from flask import Flask, request
import telebot

token = '1061.........FRozpkKCROV2Cs'
bot = telebot.TeleBot(token)
app = Flask(__name__)

@app.route('/', methods=["POST"])
def webhook():
    bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
    return "!", 200

@bot.message_handler(commands=['start'])
def command(message):
    bot.send_message(message.chat.id, 'Hi, ' + message.chat.first_name + '!')

sounds like perhaps a version mismatch?

I've created new environment and use "#!usr/venv_new/bin/python3.8", but the problem wasn't solved. Is there any problems with package pytelegrambotapi? On my pc this code works.

is this the same error message? also is this a webapp? in which case the hashbang method wouldn't work- you would need to configure it in the webapp virtualenv section and then reload your webapp.

I did:

pip install PyTelegramBotAPI==2.2.3
pip install PyTelegramBotAPI==3.6.7

And now everything works, so you were right, it was version mismatch. Thank you for your help)

Excellent, glad you got it working!

I have error ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/py thon2.7/dist-packages/pyTelegramBotAPI-3.6.7.dist-info' Consider using the --user option or check the permissions.

i try to install pip install PyTelegramBotAPI==2.2.3 pip install PyTelegramBotAPI==3.6.7

We have a help page that covers how to install modules.

Glenn, thank you so much!