The prepositions by and with are both considered prepositions of agent.
That's to say, they can both refer to situations where someone/something acts on someone/something else.
Which preposition you prefer depends on the context.
Don't distract yourselves with those phones
To say: Don't distract yourselves by those phones sounds like beside those phones.
An internet search for prepositions of agent will offer you numerous examples of where either by or with is the correct choice.
Beware, however, of using prepositions of agent when you are talking about instruments.
One frequently comes across media examples of people saying things like: killed by a sword or shot by a gun, suggesting that swords and guns go around killing people.
There was a famous example when a BBC journalist asked a British politician after a political fracas whether he had been struck by a chair.
No, said the politician, correcting his questioner's English, he had been struck by a man with a chair.