python-telegram-bot v20+: 'TypeError: Updater.__init__() got an unexpected keyword argument use_context'; v13 tutorials don't work, use Application.builder()
Rewrite v13 code to the async Application API:
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, ContextTypes, filters
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text('hi')
app = Application.builder().token(TOKEN).build()
app.add_handler(CommandHandler('start', start))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
app.run_polling() # blocking; manages its own event loopMost search results and older LLM answers still show v13: updater = Updater(TOKEN, use_context=True), dp = updater.dispatcher, Filters.text, sync handlers, updater.start_polling(); updater.idle(). On python-telegram-bot 22.8 that fails immediately with TypeError: Updater.__init__() got an unexpected keyword argument 'use_context'. telegram.ext.Filters no longer exists (it's the lowercase filters module with uppercase constants like filters.TEXT). Every handler must be async def and every Bot call awaited (await update.message.reply_text). The job queue lives at app.job_queue and needs the python-telegram-bot[job-queue] extra.
Don't wrap run_polling() in asyncio.run(). If you need your own loop (e.g. alongside FastAPI), use async with app: await app.start(); await app.updater.start_polling(). Verified in python:3.11-slim with PTB 22.8.