You can’t deter a moth from being attracted to a flame.
Or a fly being attracted to a pile of $hit.
I think this metaphor is a better one in this situation.