Ego always gets in the way. And that's a problem.
But awareness of ego and that it isn't me is a major part of the solution.
In college writing class, I was perhaps the most prolific in the class, always writing and submitting for the class to hear and critique. I knew that I needed to get the most feedback to get the most out of the class.
Rejection does tend to discourage. But it also toughens me up. Persistence is good, but you also have to know when to change and try something different. Persistently doing the wrong thing will never be successful. But sometimes you may be doing the right thing, but those who criticize don't know as much as they pretend to know. There are many success stories of best sellers making the rejection rounds through a dozen or more publishers before finding the right home.
The idea with feeling discouraged is to look at the feeling and become bigger than it. Create more of it (become cause rather than effect). Make a comedy about it. Visualize getting even; and then overdoing it (crashing planets together)! Things like this help to dislodge you from the frozen, deer in the headlights syndrome. This way, you can take a downer and turn it into an upper.
Let the energy you feel power your engine.