pythonapivk

if line similar to var then execute function


for event in longpoll.listen(): 
  if event.type == VkEventType.MESSAGE_NEW and event.to_me:
    if event.from_user: 
      request = event.text 
      line = request.lower() 
      user = event.user_id 
      if str(line) == "!add <args>" :
         print("Data has updated.")

i need if var line has arguments, like !add setting, function executes


Solution

  • The question "how to make if the line similar to /change admin the function was performed?" is not clear. Also the code expect to have indent.

    If understood correctly you need to check if the line has "/change admin" or you want to check if there is "/change" and "admin" in line, although both being same.

    If above is the case, considering line has "/change <admin/others>"

    if "/change admin" in line: # if "/change" in line and line.split(' ')[1] == "admin":
        print("Admin Changed")
    else:
        print("Usage")
    

    If you are running a command line, suggest you to use, sys module. Using sys.argv for catching command line args.

    Also look into arg_parser if looking to make some tool or utility to run command line, that gives fancy usage.