system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5 how scientists know what compounds are in the atmosphere of a planet that's light-years away

How do they figure out there's methane on titan for example?

Edit: titan was just an example because I know they discovered methane there. Yes, I know it's not light-years away. It's not a planet either. Feel free to have an imagination of a five year old.
gpt
Spectroscopy. Different elements and substances absorb different, specific wavelengths of light. You can therefore analyse the light from objects, see what wavelengths are being absorbed, and work out what it's in the atmosphere.