What does butter do in cooking?
Butter serves multiple purposes.  Butter does = flavor, particularly when the milk solids are caramelized.  Butter is also used as an emulsifier.  Butter + water or stock, can easily become a delicious sauce.  An emulsifier is also the role it plays in your example of a chocolate sauce.  It contributes to the smoothness of the chocolate sauce.  Butter plays many other roles as well.  For example in laminated dough (the dough that a croissant is made from) the butter plays the role of keeping layers of dough separate and trapping steam during baking, making a flaky pastry.