Home > Mobile >  with the api bot telegram
with the api bot telegram

Time:01-18

Please help me fix this bug in my Python code.

Error type: Update tool.init() got an unexpected argument of the keyword 'token'

Code:

# Telegram Bot API
from telegram.text import Updater

updater = Updater(token='my bot token', context_user=True)
dispatcher = updater.dispatcher

I've tried different versions of the code, I can't figure out what the error is.

CodePudding user response:

telegram-bot==3.2.0 package it working fine and passing token as following

from telegram import Updater
updater = Updater(token='token')

CodePudding user response:

  • The Updater class should be imported from telegram.ext, not text
  • For older python-bot-api versions, remove the token= part
  • Looking at the Updater() source code, there is no option called context_user, so remove that too

from telegram.ext import Updater

updater = Updater('my bot token')
  • Related