Generally, butter is used to make a recipe taste richer.
Butter itself has a nice flavor - not a strong one, but one that goes well with a lot of other flavors. And generally, recipes taste good, they taste richer, with more added fats (good energy source, so biofeedback requests more of them), and adding butter is one way to do that.
Mechanically, fats also make things slippery - one reason they're used for greasing tins for baked goods or at the bottom of cooking pans, to keep food moving. Intermixed in recipes, they make ingredients slide past each other better - for example, in a bread dough fats, when used, let the starches slide past each other a little better during kneading, instead of snagging to make gluten, meaning more kneading for the same amount of gluten formation, or a more tender result for the same amount of kneading.
Butter has a bit of water mixed in, and some milk solids suspended - it makes it possible to use as an emulsifier. Your chocolate sauce likely uses it this way - chocolate itself has starches suspended in fats (cocoa butter) and the process of changing that to a water-based sauce can be tricky because of it (seizing is what happens when things go wrong). Both cream and butter help, since they have emulsions of fats and water, having more or less of one or the other can help even out the fat and water ratios in the recipe. It may make a sauce thicken as it cools, since butter is solid at room temperature, or it may be used to thin the sauce a bit (especially when warm) since fats make things slippery.
So, there are plenty of roles fats play in recipes. The choice of which fat to use often depends on a number of factors, including texture, temperature used at, and flavor. Butter isn't generally used at high temps or for deep frying and such (unless clarified) because of its low smoke point. It is, however, often used in other ways because it has a good flavor, because it is solid at room temperature and so can form layers, or trap air, better than oils, and because it has historically been relatively easy to produce (separate cream and shake for butter, versus mechanical presses for vegetable oils or butchering and rendering for animal ones) and it was generally available to end up in a lot of recipes.