Intestinal bacterial infections have become a significant threat to human health. However, the current typical antibiotic-based therapies not only contribute to drug resistance but also disrupt gut microbiota balance, resulting in additional adverse effects on life activities. There is an urgent need to develop new antibacterial materials that selectively eliminate pathogenic bacteria without disrupting beneficial bacterial communities or promoting drug resistance. Herein, we utilize bacterial quorum sensing (QS), a universal mechanism for regulating community behavior, to develop a supramolecular QS trap by encapsulating cucurbit[7]uril (CB[7]) on 1-vinyl-3-pentylimidazolium bromide ([VPIM]Br) to form a supramolecular switch ([VPIM]Br⊂CB[7]) through host-guest interactions followed by grafting it onto bacterial cell surfaces using atom transfer radical polymerization. Subsequently, the matched pathogens are recognized and aggregated through interbacterial QS signals. Furthermore, the addition of amantadine (AD) facilitates the release of [VPIM]Br by competitive binding of CB[7] on [VPIM]Br⊂CB[7] for sterilization. This QS trap specifically triggers the self-aggregation and efficient elimination of matched bacteria. The [VPIM]Br⊂CB[7]-based trap can increase the diversity and abundance of intestinal microorganisms in mice, effectively treating Escherichia coli K88-induced intestinal damage without perturbing gut microbiota balance. This supramolecular-switched QS trap opens up a promising avenue to specifically recognize and eradicate pathogens for the antibiotic-free treatment of intestinal bacterial infections and other inflammatory diseases.