How do i detect the compounds a plant is made of, automatically?
HPLC-MS (high performance liquid chromatography- mass spectrometry), the latter with a suitable database for known small molecule plant components (alkaloids, terpenes, THC, etc.) would do it.  Cost would be three to low four figures/shot.  Saccharides and proteins are different and more expensive problems.

Consider what you are asking.  Mere pokeberry contains astragalin, canthomicrol, caryophyllene, esculentic acid, jaligonic acid, lectins, oleanolic acid, 3-oxo-30-carbomethoxy-23-norolean-12-en-28-oic acid, 6-palmityl-Δ7-stigmasterol-Δ-D-glucoside, 6-palmytityl-α-spinasteryl-6-D-glucoside, phytolaccagenic acid, phytolaccagenin, phytolaccatoxin, phytolaccosides A,B,C,D,E,F,G (esculentoside E), pokeweed mitogen, tannin, triterpene alcohols, α-spinasterol, and α-spinasteryl-β-D-glucoside and a whole bunch more.  One injection is hardly a beginning.  If you do not know how to cook it, it kills you.