Programmatically creating a custom block
I didn't find a way to display the view and restrict for certain roles.

But I've managed to solve the problem in another way.

I created a script in Admin > Structure > Block > My_Block > Configure > Visibility PHP:

&lt;?php 
$match = TRUE;
$heh = \Drupal::currentUser()-&gt;getAccount()-&gt;getRoles(TRUE);
$hide_from_roles = array('administrator', 'sefii', 'membership');
 if (count(array_intersect($heh, $hide_from_roles)) &gt; 0) {
    $match = FALSE;
}
return $match;
?&gt;