Get all users under a specific role

How can I get all users under a specific role? Is there a built-in function for this? I know I can do this using manual query but I’m hoping I can reuse a built-in function for this.

Writing the custom query is a good option. You can create a global function and can include it at a global file and so you can access it anywhere.