Textural properties provide information on the ingestibility, digestibility and state of ripeness or decay of sources of nutrition. Compared with our understanding of the chemosensory assessment of food, little is known about the mechanisms of texture detection. Here we show that Drosophila melanogaster can discriminate food texture, avoiding substrates that are either too hard or too soft. Manipulations of food substrate properties and flies’ chemosensory inputs indicate that texture preferences are revealed only in the presence of an appetitive stimulus, but are not because of changes in nutrient accessibility, suggesting that animals discriminate the substrates’ mechanical characteristics. We show that texture preference requires NOMPC, a TRP-family mechanosensory channel. NOMPC localizes to the sensory dendrites of neurons housed within gustatory sensilla, and is essential for their mechanosensory-evoked responses. Our results identify a sensory pathway for texture detection and reveal the behavioural integration of chemical and physical qualities of food.