I've heard it said many times, and when I had any worms, they did seem to zero in one coffee grounds.
I've also heard that slugs avoid coffee grounds, but I'm not sure I believe that.
However, I think my soil is too starved for worms to spend much time here. The first year I made a compost they, they arrived and thrived, but I haven't seen them since, even in my current compost heaps.
I was thrilled to go from:
"I have a few big worms"
to
"I have many small worms!"
to
"I have many medium-size worms!!"
But now I have very few worms.