Vote
Visitors can vote on a comment according to your site's Interactions settings. Interaction Mode decides what they can do. With Likes (upvote only), which is the default, they can only upvote, shown as a Like button. With Upvotes and downvotes, they can do either, and with None, voting is off.
Signed-in visitors can vote while voting is on, and guests can too if Allow Guest Interactions is on. Each person has one vote per comment, and only approved comments can be voted on. Votes can't change while a discussion is closed, and a visitor blocked from a discussion can't vote in it. Each person can vote 60 times a minute, counted per user for signed-in visitors and per IP address for guests.
To see a comment's votes in a template, use comment.getVotes(), comment.getUpvotes() and comment.getDownvotes() on the Comment, and comment.canVote() to check whether the visitor can vote. For a list of someone's votes, see Finding User Votes.
Voting on a Comment
The default templates handle this. In your own template, send a POST request with the commentId and upvote. Set upvote to 1 for an upvote, and leave it out or use 0 for a downvote, which is refused unless Interaction Mode is Upvotes and downvotes.
Voting the same way again takes the vote back, and voting the other way changes it.
{% if comment.canVote() %}
<form method="post" accept-charset="UTF-8">
{{ actionInput('comments/comments/vote') }}
{{ csrfInput() }}
{{ hiddenInput('commentId', comment.id) }}
{{ hiddenInput('upvote', 1) }}
<button type="submit">{{ 'Upvote' | t('comments') }} ({{ comment.getUpvotes() }})</button>
</form>
<form method="post" accept-charset="UTF-8">
{{ actionInput('comments/comments/vote') }}
{{ csrfInput() }}
{{ hiddenInput('commentId', comment.id) }}
{{ hiddenInput('upvote', 0) }}
<button type="submit">{{ 'Downvote' | t('comments') }} ({{ comment.getDownvotes() }})</button>
</form>
{% endif %}Leave out the second form if your site only uses likes. The visitor returns to the page they were on. If the vote wasn't accepted, such as in a closed discussion, the reason is in Craft's error flash message, which your template can show with craft.app.session.getFlash('error'). A request that accepts JSON gets success and type back instead, where type is upvote, downvote or null once the vote has been taken back.
In GraphQL
The voteComment mutation returns the vote as a VoteInterface, with the fields below. commentId and comment are only on schemas that can view comments, and userId and user only on schemas that can view users.
The ID of the comment this vote was made on.
The Comment this vote was made on.
The ID of the user who made this vote, or null for a guest.
The user who made this vote, or null for a guest.
Whether the vote is now an upvote.
Whether the vote is now a downvote. If neither is true, the vote was taken back.