I suggest two further approaches that can help (and be combined). The first one is related to Bradley Wilson's answer, but, as I hope, deviates enough from it to warrant its own introduction:
Approach 1: "Show them"
Being able to help others does make people feel good. So show them their positive skills/traits by asking for help or their opinion. The main goal is to highlight, that they are good at something others aren't, so be cautious:
- Don't ask questions that are too trivial ("what is 1 + 1 again?").
This may have the opposite effect (they can only be trusted with the easiest, most menial tasks) or create a feeling of being exploited or they may see through your scheme.
- Don't do it too frequently.
Again, this may look like exploitation and also simply annoy them. Also, it shouldn't be too one-sided.
- Something you could have found out with a little digging yourself.
Same drawbacks as Nr. 2, but there are special circumstances:
a) It could be used in situations, where Google etc. are not available.
b) Even if you can find it out on your own, you could still ask them for their assessment, because they know much more about it ("Hey, I researched X and found answers Y and Z that seemingly contradict each other. What is your opinion on this?")
- Nothing too hard for them.
If they don't know the answer, they will hardly feel better. Even worse, if they give the wrong answer / their approach doesn't work (you'd probably have to point it out)
This approach is a bit more direct, and it needs some balancing and good knowledge about your friends. It shouldn't be overdone, but maybe you come across a problem that you may solve, but am sure that they can, so you may give it a try. And the relationship should not be too one-sided, like you asking them for help all the time.
Approach 2: Tell them
Here I defer a bit from the previous answers and your question, as I agree with the other posters, that in the situation you describe, it is hard to help.
The fact that you just react to them putting themselves down, weakens your arguments. But there is certainly a reason, why you are friends or on good terms. So why not sometimes mention their good sides "out of the blue"? Surprise them, instead of just doing crisis intervention.
You vent your anger, so mention that they compare favorably to whomever ("It was so boring with X. Wished, I would have been with you instead.").
Mention their good traits, if the situation is suitable (e. g. after a good talk, tell them that, well, you can have a good talk with them. Or that they are clever/funny or that they are one of the few persons you really trust).
Pay them deserved compliments. This should be a bit more specific than something like "you look amazing", though. But be cautious, depending on the relationship you have and the expressions you use, especially comments on someone's look can be problematic (e. g. a man telling a woman that she had a "great rack").
This, again, shouldn't be overdone. And when attempting this, reflect upon yourself and how they may view you (deservedly or not), else you may appear insincere or even manipulative.