Each 3-toed sloth is taught what to eat by its mother, from whom it also inherits its particular set of bacteria, which are specialized in breaking down only leaves from the plants that the sloth eats. If the diet of the sloth is changed, for example, if it is taken out of the wild and brought into civilization to live, it cannot digest its new food, and, in the end, it will starve to death. However, I would advise against keeping a 2-toed sloth, or any other wild animal, as a pet. Although 2-toed sloths survive in captivity, it does not mean they are happy in captivity, away from the trees and birds and other sloths with whom they are familiar. However, sloths and other wild creatures do not have this ability, and human love does not meet their particular needs.
Sloths require sloth love.
Only another sloth can provide that. Instead of acquiring a sloth for your own, I hope that you will consider visiting the sloths in their native habitat, where they are as happy as sloths can be. There are a number of localities in Costa Rica and some of the other Neotropical countries where you can see sloths, if you look hard enough.