skip to Main Content

I’m creating a telegram bot using python-telegram-bot library and i want to include an handler that handle parameters.

Following this article i added a new handler using pass_args=True directive without any success

This is what i wrote so far:

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging
[...]
def parameters(bot, update, args):
    user_says = " ".join(args)
    update.message.reply_text("You said: " + user_says)

[...]

def main():
    updater = Updater(TOKEN, use_context=True)

    d = updater.dispatcher

    # Handlers
    d.add_handler(CommandHandler("start", start))
    d.add_handler(CommandHandler("parameters", parameters, pass_args=True))
    d.add_handler(CommandHandler("help", helper))


    # Start the bot
    updater.start_polling()

    # Keep it active untile CTRL + C
    updater.idle()

The problem is that when i launch the /parameter <some_text> from telegram, the Bot gave me this error:

2019-06-20 20:57:19,823 - telegram.ext.dispatcher - ERROR - An uncaught error was raised while processing the update
Traceback (most recent call last):
  File "/home/zzz/aaaa/bot/venv/lib/python3.7/site-packages/telegram/ext/dispatcher.py", line 333, in process_update
    handler.handle_update(update, self, check, context)
  File "/home/zzz/aaaa/bot/venv/lib/python3.7/site-packages/telegram/ext/handler.py", line 117, in handle_update
    return self.callback(update, context)
TypeError: parameters() missing 1 required positional argument: 'args'

What i’m doing wrong?
I’m using the latest Beta(python-telegram-bot==12.0.0b1) version.

2

Answers


  1. It is probably missing parameters on parameters:

    d.add_handler(CommandHandler("parameters", parameters(bot, update, args), pass_args=True))
    
    Login or Signup to reply.
  2. the solution always inside python telegram group

    telegram.org/#/im?p=@pythontelegrambotgroup give me the solution

     d.add_handler(CommandHandler("parameters", parameters, pass_args=True))
    

    and for the function

    def parameters(update, context):
        user_says = " ".join(context.args)
        update.message.reply_text("You said: " + user_says)
    

    The args is inside the context.args

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