How to get attachments out of a twig file
Usually ajax commands which add html are able to catch attachments bubbling up when they render the content. Don't know EmbedInsertCommand(). The name clearly says it is an command inserting html, so it should be able to do it.

For commands not able to handle attachments you can render the content already in the controller and add the attachments to the response here:

  $response = new AjaxResponse();
  $html = \Drupal::service('renderer')-&gt;renderRoot($build);
  $response-&gt;addCommand(new EmbedInsertCommand($html));
  $response-&gt;setAttachments($build['#attached']);
  return $response;


This is only a workaround, not the recommend way, because Ajax does some more processing of the attachments before adding them to the response, but for a single command this should be OK.