Skip to content

GuildChannelManager

classe · Source

Manages API methods for GuildChannels and stores their cache.

Extends: CachedManager

Properties

guild

guild: Guild

The guild this Manager belongs to Source

channelCountWithoutThreads

readonly

channelCountWithoutThreads: number

The number of channels in this managers cache excluding thread channels that do not count towards a guild's maximum channels restriction. Source

cache

cache: Collection<Snowflake, (GuildChannel|ThreadChannel)>

The cache of this Manager Source

_cache

readonly · private

_cache: Collection

The private cache of items for this manager. Source

holds

readonly · private

holds: function

The data structure belonging to this manager. Source

client

readonly

client: Client

The client that instantiated this Manager Source

Methods

resolve

resolve(channel: GuildChannelResolvable): GuildChannel | ThreadChannel

Resolves a GuildChannelResolvable to a Channel object. Parameters

NameTypeDescription
channelGuildChannelResolvableThe GuildChannel resolvable to resolve

Returns: GuildChannel \| ThreadChannelSource

resolveId

resolveId(channel: GuildChannelResolvable): Snowflake

Resolves a GuildChannelResolvable to a channel id. Parameters

NameTypeDescription
channelGuildChannelResolvableThe GuildChannel resolvable to resolve

Returns: SnowflakeSource

create

async

async create(name: string, options?: GuildChannelCreateOptions): Promise<GuildChannel>

Creates a new channel in the guild. Parameters

NameTypeDescription
namestringThe name of the new channel
options?GuildChannelCreateOptionsOptions for creating the new channel Default: {}.

Returns: Promise<GuildChannel>

js
// Create a new text channel
guild.channels.create('new-general', { reason: 'Needed a cool new channel' })
  .then(console.log)
  .catch(console.error);
js
// Create a new channel with permission overwrites
guild.channels.create('new-voice', {
  type: 'GUILD_VOICE',
  permissionOverwrites: [
     {
       id: message.author.id,
       deny: [Permissions.FLAGS.VIEW_CHANNEL],
    },
  ],
})

Source

createWebhook

async

async createWebhook(channel: GuildChannelResolvable, name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>

Creates a webhook for the channel. Parameters

NameTypeDescription
channelGuildChannelResolvableThe channel to create the webhook for
namestringThe name of the webhook
options?ChannelWebhookCreateOptionsOptions for creating the webhook

Returns: Promise<Webhook> — Returns the created Webhook

js
// Create a webhook for the current channel
guild.channels.createWebhook('222197033908436994', 'Snek', {
  avatar: 'https://i.imgur.com/mI8XcpG.jpg',
  reason: 'Needed a cool new Webhook'
})
  .then(console.log)
  .catch(console.error)

Source

addFollower

async

async addFollower(channel: NewsChannel | Snowflake, targetChannel: TextChannelResolvable, reason?: string): Promise<Snowflake>

Adds the target channel to a channel's followers. Parameters

NameTypeDescription
channelNewsChannel | SnowflakeThe channel to follow
targetChannelTextChannelResolvableThe channel where published announcements will be posted at
reason?stringReason for creating the webhook

Returns: Promise<Snowflake> — Returns created target webhook id. Source

edit

async

async edit(channel: GuildChannelResolvable, data: ChannelData, reason?: string): Promise<GuildChannel>

Edits the channel. Parameters

NameTypeDescription
channelGuildChannelResolvableThe channel to edit
dataChannelDataThe new data for the channel
reason?stringReason for editing this channel

Returns: Promise<GuildChannel>

js
// Edit a channel
guild.channels.edit('222197033908436994', { name: 'new-channel' })
  .then(console.log)
  .catch(console.error);

Source

setPosition

async

async setPosition(channel: GuildChannelResolvable, position: number, options?: SetChannelPositionOptions): Promise<GuildChannel>

Sets a new position for the guild channel. Parameters

NameTypeDescription
channelGuildChannelResolvableThe channel to set the position for
positionnumberThe new position for the guild channel
options?SetChannelPositionOptionsOptions for setting position

Returns: Promise<GuildChannel>

js
// Set a new channel position
guild.channels.setPosition('222078374472843266', 2)
  .then(newChannel => console.log(`Channel's new position is ${newChannel.position}`))
  .catch(console.error);

Source

fetch

async

async fetch(id?: Snowflake, options?: BaseFetchOptions): Promise<(?GuildChannel|ThreadChannel|Collection<Snowflake, ?GuildChannel>)>

Obtains one or more guild channels from Discord, or the channel cache if they're already available. Parameters

NameTypeDescription
id?SnowflakeThe channel's id
options?BaseFetchOptionsAdditional options for this fetch

Returns: Promise<(?GuildChannel\|ThreadChannel\|Collection<Snowflake, ?GuildChannel>)>

js
// Fetch all channels from the guild (excluding threads)
message.guild.channels.fetch()
  .then(channels => console.log(`There are ${channels.size} channels.`))
  .catch(console.error);
js
// Fetch a single channel
message.guild.channels.fetch('222197033908436994')
  .then(channel => console.log(`The channel name is: ${channel.name}`))
  .catch(console.error);

Source

fetchWebhooks

async

async fetchWebhooks(channel: GuildChannelResolvable): Promise<Collection<Snowflake, Webhook>>

Fetches all webhooks for the channel. Parameters

NameTypeDescription
channelGuildChannelResolvableThe channel to fetch webhooks for

Returns: Promise<Collection<Snowflake, Webhook>>

js
// Fetch webhooks
guild.channels.fetchWebhooks('769862166131245066')
  .then(hooks => console.log(`This channel has ${hooks.size} hooks`))
  .catch(console.error);

Source

setPositions

async

async setPositions(channelPositions: Array<ChannelPosition>): Promise<Guild>

Batch-updates the guild's channels' positions. Only one channel's parent can be changed at a time Parameters

NameTypeDescription
channelPositionsArray<ChannelPosition>Channel positions to update

Returns: Promise<Guild>

js
guild.channels.setPositions([{ channel: channelId, position: newChannelIndex }])
  .then(guild => console.log(`Updated channel positions for ${guild}`))
  .catch(console.error);

Source

delete

async

async delete(channel: GuildChannelResolvable, reason?: string): Promise<void>

Deletes the channel. Parameters

NameTypeDescription
channelGuildChannelResolvableThe channel to delete
reason?stringReason for deleting this channel

Returns: Promise<void>

js
// Delete the channel
guild.channels.delete('858850993013260338', 'making room for new channels')
  .then(console.log)
  .catch(console.error);

Source

Unofficial software. Not affiliated with or supported by Discord.