Skip to main content

CommunityMemberBanClient

CommunityMemberBanClient = TypedEventEmitter<CommunityMemberBanEvents> & object

Service client for managing member bans and kicks within a community. Bans prevent users from rejoining the community, while kicks remove users without preventing them from rejoining.

Banning or kicking a member removes them from the community, sends them a notification, posts a system message to the community's default channel, and creates a community log entry. Apps cannot be banned or kicked.

Access this client via rootServer.community.communityMemberBans.

Type Declaration

create()

create(request: CommunityMemberBanCreateRequest): Promise<CommunityMemberBan>

Bans a single member from the community. The member is removed from the community and cannot rejoin until the ban is deleted.

Parameters

ParameterTypeDescription
requestCommunityMemberBanCreateRequestIdentifies the member to ban and optional ban details.

Returns

Promise<CommunityMemberBan>

A promise that resolves to the created CommunityMemberBan object.

Throws

RootApiException with errorCode set to NoPermissionToBan if missing required permissions or attempting to ban the community owner, NotFound if the member does not exist, or NoPermissionToKick if attempting to ban an app.

Example

import {
CommunityMemberBan,
CommunityMemberBanCreateRequest,
UserGuid,
rootServer,
} from "@rootsdk/server-bot";

export async function createExample(
userId: UserGuid,
): Promise<CommunityMemberBan> {
try {
// Set up the request
const request: CommunityMemberBanCreateRequest = {
userId: userId,
reason: "Why the user should be banned from the community",
expiresAt: undefined,
};

// Call the API
const communityMemberBan: CommunityMemberBan =
await rootServer.community.communityMemberBans.create(request);

return communityMemberBan;
} catch (error) {
// Detect error
throw error;
}
}

createBulk()

createBulk(request: CommunityMemberBanCreateBulkRequest): Promise<CommunityMemberBanBulk>

Bans multiple members from the community in a single operation.

Parameters

ParameterTypeDescription
requestCommunityMemberBanCreateBulkRequestIdentifies the members to ban and optional ban details.

Returns

Promise<CommunityMemberBanBulk>

A promise that resolves to a CommunityMemberBanBulk object containing the IDs of successfully banned users.

Throws

RootApiException with errorCode set to NoPermissionToBan if missing required permissions or attempting to ban the community owner, NotFound if none of the specified members exist, or NoPermissionToKick if attempting to ban an app.

delete()

delete(request: CommunityMemberBanDeleteRequest): Promise<void>

Removes a ban, allowing the user to rejoin the community. This does not automatically add the user back to the community.

Parameters

ParameterTypeDescription
requestCommunityMemberBanDeleteRequestIdentifies the ban to delete by user ID.

Returns

Promise<void>

A promise that resolves when the ban is deleted.

Throws

RootApiException with errorCode set to NoPermissionToBan if missing required permissions, or NotFound if the ban does not exist.

Example

import {
CommunityMemberBan,
CommunityMemberBanDeleteRequest,
UserGuid,
rootServer,
} from "@rootsdk/server-bot";

export async function deleteExample(userId: UserGuid): Promise<void> {
try {
// Set up the request
const request: CommunityMemberBanDeleteRequest = {
userId: userId,
};

// Call the API
await rootServer.community.communityMemberBans.delete(request);
} catch (error) {
// Detect error
throw error;
}
}

get()

get(request: CommunityMemberBanGetRequest): Promise<CommunityMemberBan>

Retrieves a specific ban by user ID.

Parameters

ParameterTypeDescription
requestCommunityMemberBanGetRequestIdentifies the ban to retrieve.

Returns

Promise<CommunityMemberBan>

A promise that resolves to the CommunityMemberBan object.

Throws

RootApiException with errorCode set to NoPermissionToBan if missing required permissions, or NotFound if the ban does not exist.

Example

import {
CommunityMemberBan,
CommunityMemberBanGetRequest,
UserGuid,
rootServer,
} from "@rootsdk/server-bot";

export async function getExample(
userId: UserGuid,
): Promise<CommunityMemberBan> {
try {
// Set up the request
const request: CommunityMemberBanGetRequest = {
userId: userId,
};

// Call the API
const communityMemberBan =
await rootServer.community.communityMemberBans.get(request);

return communityMemberBan;
} catch (error) {
// Detect error
throw error;
}
}

kick()

kick(request: CommunityMemberBanKickRequest): Promise<void>

Kicks a single member from the community. The member is removed but can rejoin if they have an invite or the community is public.

Parameters

ParameterTypeDescription
requestCommunityMemberBanKickRequestIdentifies the member to kick.

Returns

Promise<void>

A promise that resolves when the member is kicked.

Throws

RootApiException with errorCode set to NoPermissionToKick if missing required permissions or attempting to kick an app, NoPermissionToBan if attempting to kick the community owner, or NotFound if the member does not exist.

Example

import {
CommunityMemberBan,
CommunityMemberBanKickRequest,
UserGuid,
rootServer,
} from "@rootsdk/server-bot";

export async function kickExample(userId: UserGuid): Promise<void> {
try {
// Set up the request
const request: CommunityMemberBanKickRequest = {
userId: userId,
};

// Call the API
await rootServer.community.communityMemberBans.kick(request);
} catch (error) {
// Detect error
throw error;
}
}

kickBulk()

kickBulk(request: CommunityMemberBanKickBulkRequest): Promise<CommunityMemberBanKickBulkResponse>

Kicks multiple members from the community in a single operation.

Parameters

ParameterTypeDescription
requestCommunityMemberBanKickBulkRequestIdentifies the members to kick.

Returns

Promise<CommunityMemberBanKickBulkResponse>

A promise that resolves to a CommunityMemberBanKickBulkResponse object containing the IDs of successfully kicked users.

Throws

RootApiException with errorCode set to NoPermissionToKick if missing required permissions or attempting to kick an app, NoPermissionToBan if attempting to kick the community owner, or NotFound if none of the specified members exist.

list()

list(): Promise<CommunityMemberBan[]>

Lists all active bans in the community.

Returns

Promise<CommunityMemberBan[]>

A promise that resolves to an array of CommunityMemberBan objects.

Throws

RootApiException with errorCode set to NoPermissionToBan if missing required permissions.

Example

import { CommunityMemberBan, rootServer } from "@rootsdk/server-bot";

export async function listExample(): Promise<CommunityMemberBan[]> {
try {
// Call the API
const communityMemberBans: CommunityMemberBan[] =
await rootServer.community.communityMemberBans.list();

return communityMemberBans;
} catch (error) {
// Detect error
throw error;
}
}