A dispersive solid-phase extraction method based on metal–organic framework and nitrogen–doped carbon dot nanocomposite combined with magnetic ionic liquid-based dispersive liquid–liquid microextraction was established for the extraction of aflatoxins from milk samples. For this purpose, the proteins in the sample were precipitated using a zinc sulfate solution. After vortexing (for 5 min) and centrifuging, 35 mg of the sorbent were added into the aqueous phase obtained from previous step, and the mixture was vortexed for five minutes. In the following, the sorbent particles were separated and eluted with methanol in the presence of vortex agitation (4 min). After centrifuging, the eluent phase was mixed with magnetic ionic liquid (1- octyl-3-methylimidazolium tetrachloroferrate) and rapidly injected into deionized water to perform the dispersive liquid–liquid microextraction procedure. Finally, the magnetic solvent was separated in the presence of a magnet and injected into a high-performance liquid chromatography-fluorescence detector after diluting with the mobile phase. Referring to the results, the limits of detection and quantification of the studied aflatoxins were in the ranges of 0.69–1.09 and 2.31–3.63 ng/L, respectively. Extraction recoveries were in the range of 61 to 73 %. At the end, the suggested approach was employed in the analysis of the aflatoxins in the raw cow’s milk samples collected from different regions of East Azarbaijan and AFM1 was found in several samples (34 out of 60 samples). Also, AFB1 was found in three samples.