Answer the question
In order to leave comments, you need to log in
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())
Answer the question
In order to leave comments, you need to log in
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
there is a chance you installed the wrong one ("pip install python-telegram-bot" did you do it?)
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()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question