If you investigate the reasons for thinking distracting thoughts you will find that it's based on unskillful motivations.
"Five things should be reflected on from time to time, by the bhikkhu
who is intent on the higher consciousness. What five?
When evil unskillful thoughts connected with desire, hate, and
delusion arise in a bhikkhu through reflection on an adventitious
object, he should, (in order to get rid of that), reflect on a
different object which is connected with skill. Then the evil
unskillful thoughts are eliminated; they disappear. By their
elimination, the mind stands firm, settles down, becomes unified and
concentrated, just within (his subject of meditation).
Like an experienced carpenter or carpenter's apprentice, striking hard
at, pushing out, and getting rid of a coarse peg with a fine one,
should the bhikkhu in order to get rid of the adventitious object,
reflect on a different object which is connected with skill. Then the
evil unskillful thoughts connected with desire, hate and delusion are
eliminated; they disappear. By their elimination the mind stands firm,
settles down, becomes unified and concentrated, just within (his
subject of meditation).
If the evil unskillful thoughts continue to arise in a bhikkhu, who in
order to get rid of an adventitious object reflects on a different
object which is connected with skill, he should ponder on the
disadvantages of unskillful thoughts thus: Truly these thoughts of
mine are unskillful, blameworthy, and productive of misery. Then the
evil unskillful thoughts are eliminated; they disappear. By their
elimination, the mind stands firm, settles down, becomes unified and
concentrated, just within (his subject of meditation).
Like a well-dressed young man or woman who feels horrified, humiliated
and disgusted because of the carcass of a snake, dog, or human that is
hung round his or her neck, should the bhikkhu in whom unskillful
thoughts continue to arise in spite of his reflection on the object
which is connected with skill, ponder on the disadvantages of
unskillful thoughts thus: Truly, these thoughts of mine are
unskillful, blameworthy, and productive of misery. Then the evil,
unskillful thoughts are eliminated; they disappear. By their
elimination, the mind stands firm, settles down, becomes unified and
concentrated, just within (his subject of meditation).
If evil, unskillful thoughts continue to arise in a bhikkhu who
ponders on their disadvantageousness, he should in regard to them,
endeavor to be without attention and reflection. Then the evil
unskillful thoughts are eliminated; they disappear. By their
elimination, the mind stands firm, settles down, becomes unified and
concentrated, just within (his subject of meditation).
Like a keen-eyed man shutting his eyes and looking away from some
direction in order to avoid seeing visible objects come within sight,
should the bhikkhu in whom evil, unskillful thoughts continue to arise
in spite of his pondering on their disadvantageousness, endeavor to be
without attention and reflection as regards them. Then the evil,
unskillful thoughts are eliminated; they disappear. By their
elimination, the mind stands firm, settles down, becomes unified and
concentrated, just within (his subject of meditation).
If evil, unskillful thoughts continue to arise in a bhikkhu in spite
of his endeavor to be without attention and reflection as regards
evil, unskillful thoughts, he should reflect on the removal of the
(thought) source of those unskillful thoughts. Then the evil,
unskillful thoughts are eliminated; they disappear. By their
elimination, the mind stands firm, settles down, becomes unified and
concentrated, just within (his subject of meditation).
Just as a man finding no reason for walking fast, walks slowly;
finding no reason for walking slowly, stands; finding no reason for
standing, sits down; finding no reason for sitting down, lies down,
and thus getting rid of a posture rather uncalm resorts to a restful
posture, just so should the bhikkhu in whom evil, unskillful thoughts
arise, in spite of his endeavor to be without attention and reflection
regarding them, reflect on the removal of the (thought) source of
those unskillful thoughts. Then the evil, unskillful thoughts are
eliminated; they disappear. By their elimination, the mind stands
firm, settles down, becomes unified and concentrated, just within (his
subject of meditation).
If evil, unskillful thoughts continue to arise in a bhikkhu in spite
of his reflection on the removal of a source of unskillful thoughts,
he should with clenched teeth and the tongue pressing on the palate,
restrain, subdue and beat down the (evil) mind by the (good) mind.
Then the evil, unskillful thoughts connected with desire, hate and
delusion are eliminated; they disappear. By their elimination, the
mind stands firm, settles down, becomes unified and concentrated, just
within (his subject of meditation).
Like a strong man holding a weaker man by the head or shoulders and
restraining, subduing and beating him down, should the bhikkhu in whom
evil, unskillful thoughts continue to arise in spite of his reflection
on the source of unskillful thoughts, restrain, subdue and beat down
the (evil) mind by the (good) mind, with clenched teeth and the tongue
pressing on the palate. Then the evil, unskillful thoughts connected
with desire, hate and delusion are eliminated; they disappear. By
their elimination, the mind stands firm, settles down, becomes unified
and concentrated, just within (his subject of meditation). https://www.accesstoinsight.org/tipitaka/mn/mn.020.soma.html