Answer the question
In order to leave comments, you need to log in
How to accept input arguments in user message in Telegram API?
I need the bot to accept arguments (text after the command in the bot) entered by the user immediately after the command, like in other Telegram bots. I am using pyTelegramBotApi library.
Here is a piece of code:
code = ''
@bot.message_handler(content_types=['text'])
def echo(message):
if message.text == "тест":
global code
bot.register_next_step_handler(message, code_edit)
def code_edit(message):
global code
code = message.text
Answer the question
In order to leave comments, you need to log in
Maybe not the best option, but I use something like this in my php:
>>> msg = '/cmd ping pong argumenty'
>>> args = msg.split(' ') ## переводим в массив
>>> args
['/cmd', 'ping', 'pong', 'argumenty']
>>> del args[0] ## убираем первый элемент
>>> args = ' '.join(args) ## соединяем обратно
>>> args
'ping pong argumenty'
As Steven Konrov wrote, it is possible to split the message into a command and arguments, but this is inconvenient for users and fraught with errors.
If you have a database, then you can remember the current command of each user and, depending on this, process the following messages. So the messages in the groups will not be confused.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question