CommunityRoleClient
CommunityRoleClient =
TypedEventEmitter<CommunityRoleEvents> &object
Service client for managing roles within a community. Roles define sets of permissions that can be assigned to community members, controlling what actions they can perform within the community and its channels.
Every community has a default @everyone role that cannot be deleted or renamed. Custom roles can be created with specific permission configurations and assigned to members to grant additional capabilities.
Access this client via rootServer.community.communityRoles.
Type Declaration
create()
create(
request:CommunityRoleCreateRequest):Promise<CommunityRole>
Creates a new role in the community with the specified permissions.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | CommunityRoleCreateRequest | The role configuration including name, color, and permissions. |
Returns
Promise<CommunityRole>
A promise that resolves to the created CommunityRole object.
Throws
RootApiException with errorCode set to NoPermissionToCreate if missing required permissions, or NoPermissionToAdd if attempting to grant permissions that your code does not have.
Example
import {
CommunityRole,
CommunityRoleCreateRequest,
rootServer,
} from "@rootsdk/server-bot";
export async function createExample(): Promise<CommunityRole> {
try {
// Set up the request
const request: CommunityRoleCreateRequest = {
name: "MyCommunityRole",
colorHex: "#00FF00",
isMentionable: false,
communityPermission: {
communityManageCommunity: false,
communityManageRoles: false,
communityManageEmojis: false,
communityManageAuditLog: false,
communityCreateInvite: false,
communityManageInvites: false,
communityCreateBan: false,
communityManageBans: false,
communityFullControl: false,
communityKick: false,
communityChangeMyNickname: false,
communityChangeOtherNickname: false,
communityCreateChannelGroup: false,
communityManageApps: false,
},
channelPermission: {
channelFullControl: false,
channelView: true,
channelUseExternalEmoji: false,
channelCreateMessage: true,
channelDeleteMessageOther: false,
channelManagePinnedMessages: false,
channelViewMessageHistory: false,
channelCreateMessageAttachment: false,
channelCreateMessageMention: false,
channelCreateMessageReaction: false,
channelMakeMessagePublic: false,
channelMoveUserOther: false,
channelVoiceTalk: false,
channelVoiceMuteOther: false,
channelVoiceDeafenOther: false,
channelVoiceKick: false,
channelVideoStreamMedia: false,
channelCreateFile: false,
channelManageFiles: false,
channelViewFile: false,
channelAppKick: false,
},
};
// Call the API
const communityRole: CommunityRole =
await rootServer.community.communityRoles.create(request);
return communityRole;
} catch (error) {
// Detect error
throw error;
}
}
delete()
delete(
request:CommunityRoleDeleteRequest):Promise<void>
Removes a role from the community. Members who had this role assigned will lose its permissions. The default @everyone role cannot be deleted.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | CommunityRoleDeleteRequest | Identifies the role to delete. |
Returns
Promise<void>
A promise that resolves when the delete operation completes.
Throws
RootApiException with errorCode set to NotFound if the role does not exist, or NoPermissionToDelete if missing required permissions or attempting to delete the @everyone role.
Example
import {
CommunityRoleDeleteRequest,
CommunityRoleGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function deleteExample(
communityRoleId: CommunityRoleGuid,
): Promise<void> {
try {
// Set up the request
const request: CommunityRoleDeleteRequest = {
id: communityRoleId,
};
// Call the API
await rootServer.community.communityRoles.delete(request);
} catch (error) {
// Detect error
throw error;
}
}