Understanding the principles of colonization resistance of the gut microbiome to the pathogen Clostridioides difficile will enable the design of next generation defined bacterial therapeutics. We investigate the ecological principles of community resistance to C. difficile invasion using a diverse synthetic human gut microbiome. Our results show that species richness is a key determinant of C. difficile growth across a wide range of ecological contexts. Using a dynamic computational model, we demonstrate that C. difficile receives the largest number and magnitude of incoming negative interactions. We identify molecular mechanisms of inhibition including acidification of the environment and competition over glucose. We demonstrate that C. difficile's close relative Clostridium hiranonis strongly inhibits C. difficile via a pH-independent mechanism. While increasing the initial density of C. difficile can increase its abundance in the assembled community, the community context determines the maximum achievable C. difficile abundance. Our work suggests that the C. difficile inhibitory potential of defined bacterial therapeutics can be optimized by designing communities that feature a combination of mechanisms including species richness, environment acidification, and resource competition.