Thanks for the query.
Some amount of pain abdomen and discomfort are common with increasing pregnancy
But as you are having repeated attacks of pain with features like diarrhea
better to consult gynecologist and get examined to rule out the possibility of onset of labor pains.
No need to fear if at all those are labor pains as you are almost reaching 39 weeks.