Astragalus membranaceus has complex components as a natural drug and has multilevel, multitarget, and multichannel effects on dilated cardiomyopathy (DCM). However, the immune mechanism, gene module, and molecular subtype of astragalus membranaceus in the treatment of DCM are still not revealed. Microarray information of GSE84796 was downloaded from the GEO database, including RNA sequencing data of seven normal cardiac tissues and ten DCM cardiac tissues. A total of 4029 DCM differentially expressed genes were obtained, including 1855 upregulated genes and 2174 downregulated genes. GO/KEGG/GSEA analysis suggested that the activation of T cells and B cells was the primary cause of DCM. WGCNA was used to obtain blue module genes. The blue module genes are primarily ADCY7, BANK1, CD1E, CD19, CD38, CD300LF, CLEC4E, FLT3, GPR18, HCAR3, IRF4, LAMP3, MRC1, SYK, and TLR8, which successfully divided DCM into three molecular subtypes. Based on the CIBERSORT algorithm, the immune infiltration profile of DCM was analyzed. Many immune cell subtypes, including the abovementioned immune cells, showed different levels of increased infiltration in the myocardial tissue of DCM. However, this infiltration pattern was not obviously correlated with clinical characteristics, such as age, EF, and sex. Based on network pharmacology and ClueGO, 20 active components of Astragalus membranaceus and 40 components of DMCTGS were obtained from TCMSP. Through analysis of the immune regulatory network, we found that Astragalus membranaceus effectively regulates the activation of immune cells, such as B cells and T cells, cytokine secretion, and other processes and can intervene in DCM at multiple components, targets, and levels. The above mechanisms were verified by molecular docking results, which confirmed that AKT1, VEGFA, MMP9, and RELA are promising potential targets of DCM.