The first two I find objectionable:
We are not going to do your homework for you.
First, this is false. We might, if presented in the form of a good question.
And it may presume that the question is homework, when it might be bad and basic, but not actual homework. Someone who's asking about work may feel a bit offended about that presumption.
This is a very basic question which would be better answered by a [language] textbook.
That a question is very basic is not reason enough for it being a bad question. A question may be very basic, and still on topic, narrow, answerable and useful for future users.
One down the list I also dislike:
I see many errors in this code. You should have a face-to-face conversation with your instructor about it.
Again, presuming the existence of this instructor. The existence of many errors is mostly enough. That they need to narrow their problem and work a bit more on it is good. No need to bring out that they are in need of more instruction. That's up to them (unless they bring it up directly in some other way).
All the rest, I mostly like (at varying degrees, of course). They do not mention votes, and most are specific enough to possibly be helpful for the asker.
Many of them could be improved a bit to be less confrontational, though. Kendra's advise up here is excellent.
Commenting being a source of so much friction, the more we do to smooth things out if we are going to leave negative feedback, the better.
Because, addressing the actual title of your question, if you want to "be nice and still not feed the trolls or help vampires or whatever" the best strategy might still be to vote and move on.
If you are commenting, is because you want to do something else besides "not feed" these users, right? You are doing it because you want to help. Otherwise, what's the point?