Skip to main content
Version: 0.8.0

Class: ChannelManager

Extends​

Constructors​

Constructor​

new ChannelManager(client, limit?): ChannelManager

Manages API methods and caching for all channels globally.

Parameters​

ParameterTypeDefault valueDescription
clientClientundefinedThe active Client instance.
limitnumberInfinityThe maximum number of channels to hold in the cache.

Returns​

ChannelManager

Overrides​

BaseManager<string, BaseChannel>.constructor

Properties​

cache​

cache: Collection<string, BaseChannel>

Inherited from​

BaseManager.cache


client​

client: Client

Inherited from​

BaseManager.client

Methods​

bulkDelete()​

bulkDelete(id, messages): Promise<void>

Bulk delete up to 100 messages

Parameters​

ParameterTypeDescription
idstringChannel ID
messagesMessageResolvable[]An array of MessageResolvable

Returns​

Promise<void>

Throws​

If the API request fails

Example​

await client.channels.bulkDelete("CHANNEL_ID", ["MESSAGE_ID_1", "MESSAGE_ID_2", "MESSAGE_ID_3"]);

delete()​

delete(channel): Promise<void>

Deletes a server channel, leaves a group, or closes a DM.

Parameters​

ParameterTypeDescription
channelChannelResolvableThe channel object, raw ID, or mention string to delete.

Returns​

Promise<void>

A promise that resolves when the action is successful.

Throws​

If the API request fails.

Example​

await client.channels.delete("01H...");

edit()​

edit(channel, options): Promise<BaseChannel>

Edits a channel in the server.

Parameters​

ParameterTypeDescription
channelChannelResolvableThe ChannelResolvable to edit.
optionsChannelEditOptionsThe fields to update.

Returns​

Promise<BaseChannel>

A promise that resolves to the updated BaseChannel.

Throws​

If invalid options or ChannelResolvable are provided.

Throws​

If the API request fails.

Example​

// Update channel name and remove its description
await client.channels.edit("01H...", { name: "general", description: null });

fetch()​

fetch(channel, force?): Promise<BaseChannel>

Fetches a Channel from the API or resolves it from the local cache.

Parameters​

ParameterTypeDefault valueDescription
channelChannelResolvableundefinedThe ID, mention, or Channel object to fetch.
forcebooleanfalseWhether to skip the cache check and force a direct API request. Defaults to false.

Returns​

Promise<BaseChannel>

A promise that resolves to the fetched BaseChannel object.

Throws​

If an invalid ChannelResolvable is provided.

Throws​

If the API request fails.

Example​

// Fetch a channel, bypassing cache
const channel = await client.channels.fetch("01H...");

pin()​

pin(id, messageId): Promise<void>

Pin a message

Parameters​

ParameterTypeDescription
idstringChannel ID
messageIdstringMessage ID

Returns​

Promise<void>

Throws​

If the API request fails.

Example​

await client.channels.pin("CHANNEL_ID", "MESSAGE_ID");

resolve()​

resolve(channel): BaseChannel | undefined

Resolves a ChannelResolvable to a cached BaseChannel object.

Parameters​

ParameterTypeDescription
channelChannelResolvableThe ChannelResolvable to resolve.

Returns​

BaseChannel | undefined

The resolved BaseChannel, or undefined if not cached.


resolveDM()​

resolveDM(channel): DMChannel | undefined

Parameters​

ParameterType
channelChannelResolvable

Returns​

DMChannel | undefined


resolveGroup()​

resolveGroup(channel): GroupChannel | undefined

Parameters​

ParameterType
channelChannelResolvable

Returns​

GroupChannel | undefined


resolveId()​

resolveId(channel): string

Extracts ID from a ChannelResolvable.

Parameters​

ParameterTypeDescription
channelChannelResolvableThe ChannelResolvable to extract the ID from.

Returns​

string

The extracted channel ID.

Throws​

If an invalid type is provided.


resolveText()​

resolveText(channel): TextChannel | undefined

Parameters​

ParameterType
channelChannelResolvable

Returns​

TextChannel | undefined


setDefaultPermissions()​

setDefaultPermissions(channel, permissions): Promise<BaseChannel>

Updates the default (everyone) permissions for a channel.

Parameters​

ParameterTypeDescription
channelChannelResolvableThe ChannelResolvable to update permissions for.
permissionsPermissionResolvableThe default permissions to grant globally in this channel.

Returns​

Promise<BaseChannel>

A promise that resolves to the updated BaseChannel.

Throws​

If invalid permissions are provided.

Throws​

If the API request fails.

Example​

// Set the default permission to allow everyone to view the channel
await client.channels.setDefaultPermissions(channel, ["ViewChannel", "ReadMessageHistory"]);

setRolePermissions()​

setRolePermissions(channel, roleId, options): Promise<BaseChannel>

Updates the permission overrides for a specific role in a channel.

Parameters​

ParameterTypeDescription
channelChannelResolvableThe ChannelResolvable to update permissions for.
roleIdstringThe raw string ID of the role to update.
optionsChannelRolePermissionOptionsThe allow and deny permissions to set.

Returns​

Promise<BaseChannel>

A promise that resolves to the updated BaseChannel.

Throws​

If the channel is not a Server Channel, or options are invalid.

Throws​

If the API request fails.

Example​

// Deny a role the ability to send messages in this channel
await client.channels.setRolePermissions(channel, "ROLE_ID", { deny: ["SendMessage"] });

unpin()​

unpin(id, messageId): Promise<void>

Unpin a message

Parameters​

ParameterTypeDescription
idstringChannel ID
messageIdstringMessage ID

Returns​

Promise<void>

Throws​

If the API request fails

Example​

await client.channels.unpin("CHANNEL_ID", "MESSAGE_ID");