You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

python-telegram-bot 13.7版本Updater初始化报token参数错误求助

解决方案:python-telegram-bot v13.7中Updater初始化错误

问题原因

python-telegram-bot从v12升级到v13后,Updater类的初始化参数发生了重大变化——不再直接接受token关键字参数,需要通过Bot实例或者类方法传入token。

修复代码

有两种可行的修复方式:

方式1:先创建Bot实例再传入Updater

from telegram import Bot
from telegram.ext import Updater

# 先初始化Bot对象
bot = Bot(token=TOKEN)
# 将Bot实例传入Updater
updater = Updater(bot=bot, use_context=True)

方式2:使用Updater.from_token()类方法(推荐)

这是v13版本提供的更简洁的初始化方式:

from telegram.ext import Updater

# 直接通过类方法传入token
updater = Updater.from_token(TOKEN, use_context=True)

补充说明

v13版本重构了核心组件的结构,将token的管理完全交给Bot类,Updater仅负责调度和更新处理,因此不再支持直接传入token参数。如果需要兼容旧版本代码,可考虑降级到v12.x,但更推荐适配v13的新写法。

内容的提问来源于stack exchange,提问作者Chukkala Jayanth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 10:42:35