Appearance
Class: UserRoleService
Sub-service for managing a viewer's Kappapps roles (animator, admin, superadmin): read the role, grant/revoke it, and check permissions.
Remarks
Available everywhere via k.users.role. You never have to instantiate this service yourself — it is created by the SDK when the app/widget starts.
These roles are specific to the Kappapps platform and distinct from Twitch roles (mod, VIP…), which are handled by k.users.moderation.
Example
ts
// Promote a viewer to animator, then check their permissions
await k.users.role.set('twitchdev', 'animator');
const role = await k.users.role.get('twitchdev');
console.log(k.users.role.isGranted(role, 'animator')); // trueMethods
get()
ts
get(login): Promise<string>;Reads a viewer's Kappapps role.
Parameters
login
string
The viewer's login (Twitch username).
Returns
Promise<string>
The viewer's role, or null if they cannot be found.
Example
ts
const role = await k.users.role.get('twitchdev');isGranted()
ts
isGranted(userRole, grantedRole): boolean;Checks whether a role satisfies a required permission level, taking into account the role hierarchy (superadmin ⊃ admin ⊃ animator).
Parameters
userRole
The viewer's effective role.
grantedRole
The minimum required role. If null/absent, access is always granted.
Returns
boolean
true if userRole covers grantedRole, otherwise false.
Remarks
A purely local method (no network call): useful for handling permissions on the app side without a server round-trip.
Example
ts
const role = await k.users.role.get('twitchdev');
if (k.users.role.isGranted(role, 'admin')) {
// access restricted to admins (and superadmins)
}set()
ts
set(login, role?): Promise<void>;Grants (or revokes) a Kappapps role to a viewer.
Parameters
login
string
The viewer's login (Twitch username).
role?
KappappsRoleType = null
The role to apply ('animator' or 'admin'), or null to remove it. The broadcaster's superadmin role cannot be assigned here.
Returns
Promise<void>
A promise that resolves once the operation has been sent to the backend.
Remarks
Available to widgets and official Kappapps apps only. Third-party apps receive 403 regardless of their scopes or manifest version. These are channel-level Kappapps roles, not Twitch moderator/VIP status.
Default Value
null