A man caught sexually communicating with a child on Snapchat has avoided jail.