For example, we have a command called a chart /chart Now I want to get the value that the user enters after this command
example: /chart 123456 now How should i get that 123456?
This is the code used to create the command:
def start(update: Update, context: CallbackContext) -> None:
"""Send a message when the command /start is issued."""
update.message.reply_text('Hi!')
I read the python telegram bot documents but did not find what I was looking for
3
Answers
to get argument from command line we can use module sys
$ python test.py arg1 arg2 arg3
Result:
Number of arguments: 4 arguments.
Argument List: [‘test.py’, ‘arg1’, ‘arg2’, ‘arg3’]
The code you provided is for when the user input the command
/start
.Anyway, you can get the content of the input message directly from the Update and then split the message (because it returns everything that has been written, including the command itself) by the command and obtain the input arguments to the command, like this:
To make all working correctly, you will have to add a
CommandHandler
, like this:In this way the output for
/chart 12345
will be just12345
, as shown in the picture:command executed into the telegram chat
You can also do: