For historical (and, because of, also technological) reasons most of the oil-rich countries were everything-else-poor countries, and its oil was being extracted, exported and controlled by western companies. In the 70's, they realised that the whole global economy depended on oil, and they were basically giving it out for peanuts.
They started to think about nationalizing the production and raising prices by controlling oil production, but this was a tad more complicated to do than just saying. For one side, western companies directives were friends with western governments' members, and a move against a western company, be it British Petroleum or United Fruit Co could easily end with that western company headquarters' country engaging in war with your country with a petty aliby of convenience.
For the other side, a movement like that by a single country would be severely punished by said western countries, so only a coordinated move by several countries comprising a large percentage of the oil production worldwide - and with a serious intent of not backing under threats - could achieve its objectives. Thus, OPEC was born.
If your country finds its oil resources after the oil crisis of the 70's, it can bargain a decent agreement with western oil companies without resorting to join the OPEC. Just like we have some workers' rights thanks to the deaths of many workers and unionists of yore - and specially, thanks to fear of a communist revolution after 1918 - we don't need to join a union just to have some working rights, a country just discovering oil resources now could make a fair deal without resorting to a near-war event like the oil crisis was. If it was before, though, you have all chances of being scammed by any of the oil companies out there.