skip to Main Content

I am a beginner with python-telegram-bot, I have installed version 20.0.

I installed a package "django-telegram bot" to help me integrate python-telegram-bot into django but I got an import error upon running the code

ImportError: cannot import name "Dispatcher" from telegram.ext

I delved into the python-telegram-bot package and discovered that there is no module called Dispatcher, but several online tutorials directly imported Dispatcher from telegram.ext.

2

Answers


  1. To import the dispatcher module, you’ll first need to install the python-telegram-bot package. It looks like, from the question you have done this.

    pip install python-telegram-bot
    
    

    then all you have to do is this:

    from telegram import Dispatcher
    

    it is not imported from telegram.ext. from what i can see the telegram.ext part looks like this.

    from telegram.ext import MessageHandler, Filters
    
    def handle_message(bot, update):
        message = update.message.text
        bot.send_message(chat_id=update.message.chat_id, text=message)
    
    dp.add_handler(MessageHandler(Filters.text, handle_message))
    
    

    and that reqires a bot which is derived from this:

    from telegram import Bot
    bot = Bot(token="YOUR_BOT_TOKEN")
    

    Which is different to what is suggested in the original question.

    Login or Signup to reply.
  2. The django-telegram-bot library is just not compatible with version 20 of python-telegram-bot. As you can see in the requirements file it requires the ancient version 5.3.0 of python-telegram-bot (it was released on 2016-12-11).


    Disclaimer: I’m currently the maintainer of python-telegram-bot.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search