Conditional Statement on add Role

Is there a way to add a

if (role = “admin”) {
Invite(tothischannel)
}

Essentially creating the same experience as a channel role-based permissions not invite based.Tried it in the addRolesByUserId() however it was not functioning as hoped.