To do this for all teachers globally:

Site administration > Users > Permissions > Define roles
Select the editing teacher role;
Click to edit the role
Click the Show advanced button
Type in the search box accessallgroups
When it appears, click Prevent

To do this within a course:

Course administration > Users > Permissions
Type accessallgroups into the filter
Click the X to remove from the editing teacher (Teacher) role.

https://docs.moodle.org/31/en/Groups_FAQ#How_do_I_restrict_a_teacher_to…

Tags