AttributeError: 'Updater' object has no attribute 'dispatcher': how to fix it
AttributeError: 'Updater' object has no attribute 'dispatcher' means code written for python-telegram-bot v13 is running on v20 or newer. Version 20 moved to asyncio and replaced the Updater and Dispatcher pair with Application: build it with ApplicationBuilder().token(...).build(), register handlers with application.add_handler, make the handlers async, and start with application.run_polling(). Pinning python-telegram-bot==13.15 only buys time.
By Livops team, the people who build and run LivopsUpdated
The bot stops at startup with this at the end of the traceback:
AttributeError: 'Updater' object has no attribute 'dispatcher'
The code was written for python-telegram-bot (PTB) v13 or older, and the installed PTB is v20 or newer. This page explains what v20 changed, shows the same bot before and after the rewrite, lists the errors that come from the same change, and what pinning v13 costs.
What does the error mean?
Version 20 rebuilt PTB’s structure. Updater is no longer the entry point of a PTB program, and the Dispatcher class was replaced by a new class, Application[1]. The Updater’s only job now is to fetch updates: it takes exactly two arguments, bot and update_queue, and has only those attributes[1][2][6]. There is no updater.dispatcher to add handlers to.
The other big change is asyncio. PTB no longer uses threads; every handler and job callback must be a coroutine function, async def, and every method of telegram.Bot must be awaited[1].
Which of the errors you see
v13 code breaks in several places at once, and Python stops at the first one it reaches. So the same cause shows up under different messages, depending on how the old code is written. Run on current PTB, they read:
| Error | The v13 line |
|---|---|
ImportError: cannot import name 'Filters' from 'telegram.ext' |
from telegram.ext import ..., Filters: usually the first, because it sits in the import line |
TypeError: Updater.__init__() got an unexpected keyword argument 'token' |
Updater(token=TOKEN) |
TypeError: Updater.__init__() got an unexpected keyword argument 'use_context' |
Updater(TOKEN, use_context=True) |
TypeError: Updater.__init__() missing 1 required positional argument: 'update_queue' |
Updater(TOKEN) |
AttributeError: 'Updater' object has no attribute 'dispatcher' |
updater.dispatcher, once the Updater was built with two arguments, or application.updater.dispatcher |
ImportError: cannot import name 'ParseMode' from 'telegram' |
from telegram import ParseMode, now from telegram.constants import ParseMode[1] |
On Python 3.9 and older the TypeError lines read __init__() without the class name. Adding the update_queue argument that the last TypeError asks for does not help: it only moves the failure to updater.dispatcher. All of them have one fix, the rewrite below.
Which version is installed?
Run this with the same Python the bot runs with:
pip show python-telegram-bot
PTB 20.0 came out on 1 January 2023, and 13.15, the last v13 release, a month before it[7]. A requirements.txt that says only python-telegram-bot has installed v20 or newer on every fresh install since, while an old machine still has 13.x. That is why the same code runs in one place and fails in another.
The fix: move the bot to Application
A v13 bot, close to the project’s own v13.15 example[5]. This is the code that fails:
import os
from telegram import Update
from telegram.ext import CallbackContext, CommandHandler, Filters, MessageHandler, Updater
def start(update: Update, context: CallbackContext) -> None:
update.message.reply_text("Hi!")
def echo(update: Update, context: CallbackContext) -> None:
update.message.reply_text(update.message.text)
def main() -> None:
updater = Updater(os.environ["BOT_TOKEN"])
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, echo))
updater.start_polling()
updater.idle()
if __name__ == "__main__":
main()
On current PTB it stops at the Filters import first; each line it reaches after that is one of the errors in the table above.
The same bot for v20 and later, following the current example[4]:
import logging
import os
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, MessageHandler, filters
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text("Hi!")
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(update.message.text)
def main() -> None:
application = ApplicationBuilder().token(os.environ["BOT_TOKEN"]).build()
application.add_handler(CommandHandler("start", start))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
application.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
main()
What changed, line by line:
ApplicationBuilder().token(...).build()instead ofUpdater(TOKEN). The Application is created with a builder: you set what you need on it, then callbuild()[1].Application.builder()returns the same builder[3].application.add_handler(...)instead ofdispatcher.add_handler(...). The handler classes,CommandHandlerandMessageHandler, keep their names.async defhandlers, andawaiton every Bot call,reply_textincluded[1]. A call withoutawaitis never sent; Python only printsRuntimeWarning: coroutine '...' was never awaited[13].filters.TEXTinstead ofFilters.text.telegram.ext.Filtersno longer exists; use the moduletelegram.ext.filters. Filters that need no arguments are in capitals (filters.TEXT,filters.COMMAND), filter classes that take arguments are in CamelCase (filters.User), and related filters are grouped: any document isfilters.Document.ALL[1].ContextTypes.DEFAULT_TYPEas the type ofcontext, as the current examples write it[4].run_polling()instead ofstart_polling()plusidle(). It initializes and starts the app, polls, and blocks until it receives a stop signal, by default SIGINT, SIGTERM or SIGABRT outside Windows, then shuts down cleanly[3]. Call it from a plaindef main(), as above, not from insideasyncio.run(): why is in This event loop is already running.
Three more things old code often uses:
- Constants and errors moved into modules.
from telegram import ParseModebecomesfrom telegram.constants import ParseMode, and errors are imported fromtelegram.error[1]. - JobQueue is an optional extra. Since v20 only
httpxis installed by default[1]. If the bot schedules jobs, putpython-telegram-bot[job-queue]inrequirements.txt[12]. - There is a transition script. The PTB wiki links a regex-based script that does part of the search and replace. Its authors say it is no substitute for reading the guide and fixing the code by hand[1].
Pinning 13.15: the short-term option
The quick way out is to install the version the code was written for:
python-telegram-bot==13.15
The bot runs again, and the cost grows with time:
- No more v13 releases. 13.15, from December 2022, is the last; everything since is v20 or later[7].
- Old pinned dependencies. 13.15 pins
tornado==6.1andAPScheduler==3.6.3exactly[8]. tornado 6.1 ships ready-built wheels only up to Python 3.9[9], so on a newer Python pip builds it from source. When that fails, see Failed building wheel. - Python 3.13 breaks it. 13.15 does
import imghdrintelegram/files/inputfile.py[10], a module loaded as soon as you importtelegram. Python 3.13 removedimghdrfrom the standard library[11], so on 3.13 or newer the bot stops atModuleNotFoundError: No module named 'imghdr'before any of your code runs.
If you pin, pin Python 3.12 or older with it, and use the time to do the rewrite. The current PTB release needs Python 3.10 or newer[7].
On Livops
What Livops does with a python-telegram-bot bot, and what it does not:
-
It installs what
requirements.txtnames. An unpinnedpython-telegram-botline gets the current release on every deploy, the same as on any fresh machine. Once the code is rewritten, write the major version you tested, for examplepython-telegram-bot>=22,<23. -
The error stops the deploy as
start_failed. The build passes, the bot fails as it starts, and the traceback is on the project’s Logs page. A bot’s previous version is stopped before the new one starts, because two copies polling Telegram would conflict, so the bot is down until a deploy succeeds. Run the rewritten bot locally first. -
You choose the Python. Livops runs Python 3.10 to 3.14 and reads the version from a
.python-versionfile at the project root. For the 13.15 stopgap, use 3.12 or older:3.12 -
The start command. Livops finds
bot.py,main.py,app.pyorrun.pyby itself. To name it, write.venv/bin/python bot.pyin Settings → Start, or aProcfile:worker: .venv/bin/python bot.py -
The token is a variable. Put it under Settings → Variables as
BOT_TOKEN, which the code above reads.
A bot costs 19 credits a month (19,000 so’m). A VPS is the better fit when you run many bots on one machine, or a bot needs root for system packages of its own; on Livops a push is the deploy and restarts are the platform’s job, but there is no root. Hosting details are in python-telegram-bot hosting, and startup failures in The app did not start.
Questions
Why did this start without any change to my code?
Your requirements.txt names python-telegram-bot without a version, so a fresh install picked the current release, which is v20 or newer. The code was written for v13. Check the installed version with pip show python-telegram-bot.
Where did the Dispatcher go?
Version 20 replaced the Dispatcher class with Application, which is now the entry point of the program. Handlers are added to the application with application.add_handler, and the Updater only fetches updates.
Is Filters.text the same as filters.TEXT?
Yes. telegram.ext.Filters no longer exists; use the lowercase module telegram.ext.filters. Filters that need no arguments are written in capitals, such as filters.TEXT and filters.COMMAND.
What replaces updater.idle()?
application.run_polling(). It starts the bot, keeps it running until it receives a stop signal such as Ctrl+C or SIGTERM, and shuts it down cleanly.
Is pinning python-telegram-bot 13.15 a real fix?
It is a stopgap. 13.15 is the last v13 release, from December 2022. It pins old dependencies and cannot be imported on Python 3.13 or newer, because it imports the imghdr module that Python 3.13 removed.
Do I have to make every handler async?
Yes. From v20 every handler and job callback must be a coroutine function, async def, and every Bot method call must be awaited. A call without await never runs, and Python prints a RuntimeWarning that the coroutine was never awaited.
Does Livops rewrite v13 code for me?
No. Livops installs what requirements.txt names and starts your bot. When the bot fails at startup, the deploy stops as start_failed and the traceback is on the Logs page; the rewrite is yours.
Sources
- python-telegram-bot wiki — Transition guide to Version 20.0 (github.com). Checked .
- python-telegram-bot docs — telegram.ext.Updater (docs.python-telegram-bot.org). Checked .
- python-telegram-bot docs — telegram.ext.Application (docs.python-telegram-bot.org). Checked .
- python-telegram-bot — examples/echobot.py (github.com). Checked .
- python-telegram-bot v13.15 — examples/echobot.py (github.com). Checked .
- python-telegram-bot source — telegram/ext/_updater.py (github.com). Checked .
- PyPI — python-telegram-bot, release history (pypi.org). Checked .
- PyPI — python-telegram-bot 13.15 (pypi.org). Checked .
- PyPI — tornado 6.1, files (pypi.org). Checked .
- python-telegram-bot v13.15 source — telegram/files/inputfile.py (github.com). Checked .
- Python docs — What's New In Python 3.13 (docs.python.org). Checked .
- python-telegram-bot — README, optional dependencies (github.com). Checked .
- Python docs — Developing with asyncio (docs.python.org). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- python-telegram-bot hosting: deploying a v22 botA python-telegram-bot bot runs as one Application: run_polling() for polling, run_webhook() with the webhooks extra for a webhook. Both stop cleanly on SIGTERM. On Livops it runs from a push with bot.py and requirements.txt for 19 credits a month (19,000 so'm).
- RuntimeError: This event loop is already running — how to fix it in a Telegram botRuntimeError: This event loop is already running, and its sibling asyncio.run() cannot be called from a running event loop, mean the code tried to start an asyncio event loop inside one that is already running: python-telegram-bot's run_polling inside your own asyncio.run, aiogram's run_polling inside an async main, asyncio.run inside a handler, or a Jupyter notebook. Start the loop once, at the bottom of the program, and await everything inside it.
- RuntimeError: Event loop is closed — how to fix it in Python asyncioRuntimeError: Event loop is closed means code asked an asyncio event loop to do something after that loop had been closed: an aiohttp or httpx client created inside one asyncio.run() and used in the next, a session closed after the program's loop ended, python-telegram-bot's run_polling() restarted in the same process, or, on Windows, a transport cleaned up at exit. Create clients inside the running loop, close them before it ends, and run the loop once.
- Conflict: terminated by other getUpdates request — how to fix itTelegram is telling your bot that another process called getUpdates with the same token and took the connection over. Two copies of the bot are polling at once: stop the other one (usually the copy still running on your computer or an old server), or get a new token from @BotFather, and the error stops.
- ModuleNotFoundError: No module named — after a deployPython searched sys.path and could not find the module you import. After a deploy that almost always means the package is not in requirements.txt, is listed under a different name than the one you import, or the start command runs a Python that the packages were not installed into.
- pip: Failed building wheel / failed-wheel-build-for-install — how to fix itpip found no ready-made wheel for a package on your Python version and platform, tried to compile one from source, and the compiler step failed. The fix is almost never to install a compiler: move to a version of the package that ships a wheel for your Python, switch to its binary variant (psycopg[binary], psycopg2-binary), or pin the Python version the package supports.
- Telegram bot hosting in 2026: the options comparedA Telegram bot needs a process that never stops, or a public HTTPS address for a webhook. On Livops it runs from a GitHub push for 19 credits a month (19,000 so'm). Here is how a VPS, Railway, Render, Fly.io and Vercel compare.