How to disable the comment for a specific node programmatically? I'm using Drupal 8. I would like to close the comment for the node, once someone commented on that node. But I don't know how to disable the comment for a specific node programmatically.

my_module_comment_insert ($entity) //implement the comment insert hook
{
    $node = $entity-&gt;getCommentedEntity();//get the attached comment node.
    // How to implement code here to disable comment for the $node? 
}
In D8, the comments are stored as field containing various comment properties including comment status.

You can disable node/entity comments using something like below:

use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;

/**
 * Implements hook_comment_insert().
 */
function [MODULE_NAME]_comment_insert($comment) {
  // Get comment field name, default comment.
  $field_name = 'comment'; // $comment-&gt;getFieldName();

  // Get entity.
  $node = $comment-&gt;getCommentedEntity();
  $node-&gt;get($field_name)-&gt;status = CommentItemInterface::CLOSED;
  $node-&gt;save();
}