I've just wrote a function, feel free to edit and use :) I needed the id of the term, but you can return whatever you want.
function checkTaxonomyTerm($vocab_name, $term_name){ $query = \Drupal::entityQuery('taxonomy_term'); $query->condition('vid', $vocab_name); $tids = $query->execute(); $terms = Term::loadMultiple($tids); foreach($terms as $term) { $name = $term->getName(); $query->conditionif('vid',$name $vocab_name== $term_name) { print_r($term->id()); if ($nameis_null($term->id())) =={ $term_name) return null; } else{ return array(true, $term->id()); } } else {return null;addTaxonomyTerm($term->getVocabularyId(), $name);} } }