diff --git a/src/managers/GuildChannelManager.js b/src/managers/GuildChannelManager.js index d2871e599acf..46787773f7a1 100644 --- a/src/managers/GuildChannelManager.js +++ b/src/managers/GuildChannelManager.js @@ -93,18 +93,8 @@ class GuildChannelManager extends CachedManager { /** * Options used to create a new channel in a guild. - * @typedef {Object} GuildChannelCreateOptions - * @property {ChannelType|number} [type='GUILD_TEXT'] The type of the new channel. - * @property {string} [topic] The topic for the new channel - * @property {boolean} [nsfw] Whether the new channel is nsfw - * @property {number} [bitrate] Bitrate of the new channel in bits (only voice) - * @property {number} [userLimit] Maximum amount of users allowed in the new channel (only voice) + * @typedef {CategoryCreateChannelOptions} GuildChannelCreateOptions * @property {CategoryChannelResolvable} [parent] Parent of the new channel - * @property {OverwriteResolvable[]|Collection} [permissionOverwrites] - * Permission overwrites of the new channel - * @property {number} [position] Position of the new channel - * @property {number} [rateLimitPerUser] The ratelimit per user for the new channel - * @property {string} [reason] Reason for creating the new channel */ /** diff --git a/src/structures/CategoryChannel.js b/src/structures/CategoryChannel.js index c5727bb0086c..b6b198f1b239 100644 --- a/src/structures/CategoryChannel.js +++ b/src/structures/CategoryChannel.js @@ -26,6 +26,35 @@ class CategoryChannel extends GuildChannel { * @param {SetParentOptions} [options={}] The options for setting the parent * @returns {Promise} */ + + /** + * Options for creating a channel using {@link CategoryChannel#createChannel}. + * @typedef {Object} CategoryCreateChannelOptions + * @property {ChannelType|number} [type='GUILD_TEXT'] The type of the new channel. + * @property {string} [topic] The topic for the new channel + * @property {boolean} [nsfw] Whether the new channel is nsfw + * @property {number} [bitrate] Bitrate of the new channel in bits (only voice) + * @property {number} [userLimit] Maximum amount of users allowed in the new channel (only voice) + * @property {OverwriteResolvable[]|Collection} [permissionOverwrites] + * Permission overwrites of the new channel + * @property {number} [position] Position of the new channel + * @property {number} [rateLimitPerUser] The ratelimit per user for the new channel + * @property {string} [reason] Reason for creating the new channel + */ + + /** + * Creates a new channel on this category. + * You cannot create a channel of type `GUILD_CATEGORY` inside a CategoryChannel. + * @param {string} name The name of the new channel + * @param {CategoryCreateChannelOptions} options Options for creating the new channel + * @returns {Promise} + */ + createChannel(name, options) { + return this.guild.channels.create(name, { + ...options, + parent: this.id, + }); + } } module.exports = CategoryChannel; diff --git a/typings/index.d.ts b/typings/index.d.ts index dc600d75a47f..c824bfa7b390 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -390,6 +390,30 @@ export class ButtonInteraction extends MessageComponentInteraction { export class CategoryChannel extends GuildChannel { public readonly children: Collection; public type: 'GUILD_CATEGORY'; + public createChannel( + name: string, + options: CategoryCreateChannelOptions & { type: 'GUILD_VOICE' }, + ): Promise; + public createChannel( + name: string, + options?: CategoryCreateChannelOptions & { type?: 'GUILD_TEXT' }, + ): Promise; + public createChannel( + name: string, + options: CategoryCreateChannelOptions & { type: 'GUILD_NEWS' }, + ): Promise; + public createChannel( + name: string, + options: CategoryCreateChannelOptions & { type: 'GUILD_STORE' }, + ): Promise; + public createChannel( + name: string, + options: CategoryCreateChannelOptions & { type: 'GUILD_STAGE_VOICE' }, + ): Promise; + public createChannel( + name: string, + options: CategoryCreateChannelOptions, + ): Promise; } export type CategoryChannelResolvable = Snowflake | CategoryChannel; @@ -3282,6 +3306,34 @@ export type CacheWithLimitsOptions = { : never; }; +export interface CategoryCreateChannelOptions { + permissionOverwrites?: OverwriteResolvable[] | Collection; + topic?: string; + type?: Exclude< + keyof typeof ChannelTypes | ChannelTypes, + | 'DM' + | 'GROUP_DM' + | 'UNKNOWN' + | 'GUILD_PUBLIC_THREAD' + | 'GUILD_NEWS_THREAD' + | 'GUILD_PRIVATE_THREAD' + | 'GUILD_CATEGORY' + | ChannelTypes.DM + | ChannelTypes.GROUP_DM + | ChannelTypes.UNKNOWN + | ChannelTypes.GUILD_PUBLIC_THREAD + | ChannelTypes.GUILD_NEWS_THREAD + | ChannelTypes.GUILD_PRIVATE_THREAD + | ChannelTypes.GUILD_CATEGORY + >; + nsfw?: boolean; + bitrate?: number; + userLimit?: number; + rateLimitPerUser?: number; + position?: number; + reason?: string; +} + export interface ChannelCreationOverwrites { allow?: PermissionResolvable; deny?: PermissionResolvable; @@ -3910,29 +3962,23 @@ export interface GuildChannelOverwriteOptions { export type GuildChannelResolvable = Snowflake | GuildChannel | ThreadChannel; -export interface GuildChannelCreateOptions { - permissionOverwrites?: OverwriteResolvable[] | Collection; - topic?: string; +export interface GuildChannelCreateOptions extends Omit { + parent?: CategoryChannelResolvable; type?: Exclude< keyof typeof ChannelTypes | ChannelTypes, | 'DM' | 'GROUP_DM' | 'UNKNOWN' | 'GUILD_PUBLIC_THREAD' + | 'GUILD_NEWS_THREAD' | 'GUILD_PRIVATE_THREAD' | ChannelTypes.DM | ChannelTypes.GROUP_DM | ChannelTypes.UNKNOWN | ChannelTypes.GUILD_PUBLIC_THREAD + | ChannelTypes.GUILD_NEWS_THREAD | ChannelTypes.GUILD_PRIVATE_THREAD >; - nsfw?: boolean; - parent?: CategoryChannelResolvable; - bitrate?: number; - userLimit?: number; - rateLimitPerUser?: number; - position?: number; - reason?: string; } export interface GuildChannelCloneOptions extends GuildChannelCreateOptions {