Is there a way to show a message to specific users? I would like to programmatically set a message shown at least once for selected users or for all users with a specific role.
Copy the following snippet to your module, then you have to replace MODULE with your module machine name

/**
 * Implements hook_preprocess_HOOK().
 */
function MODULE_preprocess_page(&amp;$variables) {
  $message = t("You have been served!");
        $request = \Drupal::request();
  $session = $request-&gt;getSession();
  $message_was_displayed = $session-&gt;get('mymodule_message_was_displayed', FALSE);
  if ($message_was_displayed === FALSE) {
    $messenger = \Drupal::messenger();
    $messenger-&gt;addMessage($message);
    $session-&gt;set('mymodule_message_was_displayed', TRUE);
  }
}