how to get groups' name info by code?

as title,I want to get a user's group name and extract info save to other place, user() don't contain user's info, how to do it?

  Discussion posts and replies are publicly visible