How do I display username in a custom block?
You can do this in sevaral ways, one of this could be use a preprocess function. In your custom module in the .module file or your custom theme in the .theme file (recommended) write this:

/**
 * Implements hook_preprocess_HOOK().
 */
function [my_module_or_theme]_preprocess_block(&amp;$variables) {
  $variables['username'] = \Drupal::currentUser()-&gt;getUsername();
} 


and then in your template suggestions of block.twig.html print the variable {{ username }}