You cannot prevent a dusting attack, but there are measures to prevent consequences. Convert dust if your platform allows it, use hierarchical-deterministic wallets, or flag the received crypto so that you don’t use it.