GuildChannelManager
classe · Source
Manages API methods for GuildChannels and stores their cache.
Extends: CachedManager
Properties
guild
The guild this Manager belongs to Source
channelCountWithoutThreads
The number of channels in this managers cache excluding thread channels that do not count towards a guild's maximum channels restriction. Source
cache
The cache of this Manager Source
_cache
The private cache of items for this manager. Source
holds
The data structure belonging to this manager. Source
client
The client that instantiated this Manager Source
Methods
resolve
Resolves a GuildChannelResolvable to a Channel object. Parameters
| Name | Type | Description |
|---|---|---|
channel | GuildChannelResolvable | The GuildChannel resolvable to resolve |
Returns: GuildChannel \| ThreadChannelSource
resolveId
Resolves a GuildChannelResolvable to a channel id. Parameters
| Name | Type | Description |
|---|---|---|
channel | GuildChannelResolvable | The GuildChannel resolvable to resolve |
Returns: SnowflakeSource
create
Creates a new channel in the guild. Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the new channel |
options? | GuildChannelCreateOptions | Options for creating the new channel Default: {}. |
Returns: Promise<GuildChannel>
// Create a new text channel
guild.channels.create('new-general', { reason: 'Needed a cool new channel' })
.then(console.log)
.catch(console.error);// 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],
},
],
})createWebhook
Creates a webhook for the channel. Parameters
| Name | Type | Description |
|---|---|---|
channel | GuildChannelResolvable | The channel to create the webhook for |
name | string | The name of the webhook |
options? | ChannelWebhookCreateOptions | Options for creating the webhook |
Returns: Promise<Webhook> — Returns the created Webhook
// 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)addFollower
Adds the target channel to a channel's followers. Parameters
| Name | Type | Description |
|---|---|---|
channel | NewsChannel | Snowflake | The channel to follow |
targetChannel | TextChannelResolvable | The channel where published announcements will be posted at |
reason? | string | Reason for creating the webhook |
Returns: Promise<Snowflake> — Returns created target webhook id. Source
edit
Edits the channel. Parameters
| Name | Type | Description |
|---|---|---|
channel | GuildChannelResolvable | The channel to edit |
data | ChannelData | The new data for the channel |
reason? | string | Reason for editing this channel |
Returns: Promise<GuildChannel>
// Edit a channel
guild.channels.edit('222197033908436994', { name: 'new-channel' })
.then(console.log)
.catch(console.error);setPosition
Sets a new position for the guild channel. Parameters
| Name | Type | Description |
|---|---|---|
channel | GuildChannelResolvable | The channel to set the position for |
position | number | The new position for the guild channel |
options? | SetChannelPositionOptions | Options for setting position |
Returns: Promise<GuildChannel>
// Set a new channel position
guild.channels.setPosition('222078374472843266', 2)
.then(newChannel => console.log(`Channel's new position is ${newChannel.position}`))
.catch(console.error);fetch
Obtains one or more guild channels from Discord, or the channel cache if they're already available. Parameters
| Name | Type | Description |
|---|---|---|
id? | Snowflake | The channel's id |
options? | BaseFetchOptions | Additional options for this fetch |
Returns: Promise<(?GuildChannel\|ThreadChannel\|Collection<Snowflake, ?GuildChannel>)>
// Fetch all channels from the guild (excluding threads)
message.guild.channels.fetch()
.then(channels => console.log(`There are ${channels.size} channels.`))
.catch(console.error);// Fetch a single channel
message.guild.channels.fetch('222197033908436994')
.then(channel => console.log(`The channel name is: ${channel.name}`))
.catch(console.error);fetchWebhooks
Fetches all webhooks for the channel. Parameters
| Name | Type | Description |
|---|---|---|
channel | GuildChannelResolvable | The channel to fetch webhooks for |
Returns: Promise<Collection<Snowflake, Webhook>>
// Fetch webhooks
guild.channels.fetchWebhooks('769862166131245066')
.then(hooks => console.log(`This channel has ${hooks.size} hooks`))
.catch(console.error);setPositions
Batch-updates the guild's channels' positions. Only one channel's parent can be changed at a time Parameters
| Name | Type | Description |
|---|---|---|
channelPositions | Array<ChannelPosition> | Channel positions to update |
Returns: Promise<Guild>
guild.channels.setPositions([{ channel: channelId, position: newChannelIndex }])
.then(guild => console.log(`Updated channel positions for ${guild}`))
.catch(console.error);delete
Deletes the channel. Parameters
| Name | Type | Description |
|---|---|---|
channel | GuildChannelResolvable | The channel to delete |
reason? | string | Reason for deleting this channel |
Returns: Promise<void>
// Delete the channel
guild.channels.delete('858850993013260338', 'making room for new channels')
.then(console.log)
.catch(console.error);