Some animals change their feeding behaviour when infected with parasites, seeking out substances that enhance their ability to overcome infection. This 'self-medication' is typically considered to involve the consumption of toxins, minerals or secondary compounds. However, recent studies have shown that macronutrients can influence the immune response and that pathogen-challenged individuals can self-medicate by choosing a diet rich in protein and low in carbohydrates. Infected individuals might also reduce food intake when infected (i.e. illness-induced anorexia). Here, we examine macronutrient self-medication and illness-induced anorexia in caterpillars of the African armyworm (Spodoptera exempta) by asking how individuals change their feeding decisions over the time course of infection with a baculovirus. We measured self-medication behaviour across several full-sib families to evaluate the plasticity of diet choice and underlying genetic variation. Larvae restricted to diets high in protein (P) and low in carbohydrate (C) were more likely to survive a virus challenge than those restricted to diets with a low P : C ratio. When allowed free choice, virus-challenged individuals chose a higher protein diet than controls. Individuals challenged with either a lethal or sublethal dose of virus increased the P : C ratio of their chosen diets. This was mostly due to a sharp decline in carbohydrate intake, rather than an increased intake of protein, reducing overall food intake, consistent with an illness-induced anorexic response. Over time the P : C ratio of the diet decreased until it matched that of controls. Our study provides the clearest evidence yet for dietary self-medication using macronutrients and shows that the temporal dynamics of feeding behaviour depends on the severity and stage of the infection. The strikingly similar behaviour shown by different families suggests that self-medication is phenotypically plastic and not a consequence of genetically based differences in diet choice between families.