How to assign a group to a user in PHP
Apparently this is the right way to do it:

$user = User::find()-&gt;username($username)-&gt;one();
Craft::$app-&gt;users-&gt;assignUserToGroups($user-&gt;id, [1]);


It's unclear how setGroups is supposed to work.