P
P
PeteDoherty2021-09-01 00:28:04
Python
PeteDoherty, 2021-09-01 00:28:04

What is the reason for the error in importing the Telegram module?

Hello. I encountered the following problem: when importing the telegram module (python-telegram-bot), an error pops up in the traceback "module 'telegram' has no attribute 'Bot'". Moreover, an error occurred when testing the usual code from the documentation.

import telegram
bot = telegram.Bot(token='TOKEN')
print(bot.get_me())


The module itself was deleted several times and re-installed in the terminal. Tell me what could be the reason?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
agent_2203, 2021-09-01
@agent_2203

Make sure you don't have packages installed that can be imported instead of this library
pip3 list | grep -i telegram
. If there are, then remove them and reinstall the library again.

pip3 install --user --force-reinstall python-telegram-bot

A
Artem Imaev, 2021-09-01
@AIRC24

there is a chance you installed the wrong one ("pip install python-telegram-bot" did you do it?)

A
Adrian Makridenko, 2021-09-01
@maccree

Try with updater

from telegram.ext import Updater

updater = Updater(token='<YOUR TOKEN HERE>')    
dispatcher = updater.dispatcher

def startCommand(bot, update):
    bot.send_message(chat_id=update.message.chat_id, text='Hello!')

start_command_handler = CommandHandler('start', startCommand)
updater.start_polling(clean=True)
updater.idle()

I don’t know if it will help or not, but I got out like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question