Well... that's actually a VERY COMPLEX question, with NO straightforward easy answer.
Depending upon the situation, you could begin by doing this:
1) First, tell your friend that you noticed he/she is really feeling down.
2) Next, you can tell your friend that you actually went out of your way to post an Internet forum discussion question (such as this particular question on Reddit) about how to cheer up your friend.
That will, demonstrate to your friend that you really care about them, since you went to the trouble of thinking about their situation, and you are actually seeking help from a large online community.
Even if they don't say it out loud, they will like the fact that there is someone else in the world that cares this much about them.
3) Next, you can also tell your friend that you are aware that trying to go out of your way to "cheer" someone up can often be the WRONG thing to do!
Sometimes when we are going through something very traumatic, or difficult in life, the LAST THING we want is a bunch of people trying to "cheer" us up, or make us "snap" out of it.
INSTEAD: sometimes we have to go through a period of sadness, melancholy, and depression.
Such moments are COMPLETELY NORMAL, and a PART OF LIFE.
4) At the same time, after telling your friend you are aware that trying to "cheer" someone up is sometimes the wrong thing to do (since we all have to sometimes go through periods of melancholy/depression) you can make a few little jokes, if you think it is appropriate, and actually do have a couple of funny jokes.
When making the joke, you could then just say:
"Sorry... I couldn't help trying to make a joke or two to cheer you up, even though I know it's normal/important for you to go through this down time."
But don't overdo it on the jokes to excess, as that can get really annoying!
5) FINALLY... keep in mind that some types of depression/melancholy are the result of a bio-chemical imbalance within the human brain, or an actual physical/structural issue with the human brain (related to the mapping/shaping of physical neural networks in the brain).
If it is a physical/biochemical situation within your friend's brain, then NO AMOUNT of trying to cheer them up will help.
You can NOT just magically whisk away a biochemical issue, or physical/structural issue in someone's brain, just by making a few clever jokes, or drinking a few glasses of alcohol, or going out for a fun night on the town, or throwing a ton of money at the person.
In such cases, the physical or biochemical issue in their brain will remain, no matter how much energy/time you put into trying to "cheer" them up, and instead that person MIGHT need the help of medicine.
In short... it's perfectly NORMAL to go through a relatively long period of melancholy or depression in life... And sometimes a person does NOT want to "cheered up" but rather they might just want to have a good friend for them, there, as they go through the issue.
But sometimes the problem can be far greated, and be biochemical or physical-medical in nature... or a very complex psychological issue that is beyond the ability of any friend to help with.