How are commands with options made? Python Telegram

Question:

Tell me how to make a command with options for a bot in telegrams (pytelegrambotapi)? For example:

/sendalluser привет

you do not understand .. I need to make a command with options, that is, someone, for example, writes / check 8 and if I have this number in the given array, then I process this option ….

Answer:

Commands are added via BotFather , not programmatically:

/ mybots > @your_bot > Edit Bot > Edit Commands

When adding a command to your bot, add a short and clear description for the user – it will be displayed in the list of commands.


Using commands with parameters is no different from normal message processing – you need to programmatically process such messages taking into account that the command may / may not have parameters.
In this case, for example, you can process the received message as follows ( pseudocode ):

if (message.text == sendalluser)
{
   var s = split(message.text, ' ');
   var option = "Пока";
   if (s.count > 1) 
   {
      option = s[1];
   }

   bot.send(chatId, option);
}
Scroll to Top