there is no mandatory version "flag" or define or variable number when you develop a library, so the concept of version does not make general sense unfortunately.
well conceived libraries you download through the IDE contain a library.properties file (for example https://github.com/jandrassy/ArduinoOTA/blob/master/library.properties or https://github.com/knolleary/pubsubclient/blob/master/library.properties, ..) with a version field.
may be by extracting the verbose output of the compilation you can build something that matches your need. For example (translated) that's what I see when compiling a project I'm working on
Using library SPIFFS version 1.0 in directory: ~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/SPIFFS
Using library FS version 1.0 in directory: ~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/FS
Using library WiFi version 1.0 in directory: ~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi
Using library WiFiManager version 2.0.4-beta in directory: ~/Documents/Arduino/libraries/WiFiManager
Using library Update version 1.0 in directory: ~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/Update
Using library WebServer version 1.0 in directory: ~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WebServer
Using library DNSServer version 1.1.0 in directory: ~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/DNSServer
Using library ArduinoOTA version 1.0 in directory: ~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/ArduinoOTA
Using library pubsubclient version 2.8 in directory: ~/Documents/Arduino/libraries/pubsubclient
Using library ESPmDNS version 1.0 in directory: ~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/ESPmDNS