From 2966dac4ac33afcfebb4335dd6d076d26bf3d7f1 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Wed, 8 Sep 2021 23:35:50 +0100 Subject: [PATCH 1/3] feat(CategoryChannel): add createChannel shortcut method --- src/managers/GuildChannelManager.js | 12 +----- src/structures/CategoryChannel.js | 29 +++++++++++++ typings/index.d.ts | 66 ++++++++++++++++++++++++----- 3 files changed, 86 insertions(+), 21 deletions(-) diff --git a/src/managers/GuildChannelManager.js b/src/managers/GuildChannelManager.js index fc7a7e47b116..aff85f548d34 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..ccd06879f910 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, { + parent: this.id, + ...options, + }); + } } module.exports = CategoryChannel; diff --git a/typings/index.d.ts b/typings/index.d.ts index 192c52528409..0ef6c675fb49 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -387,6 +387,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; @@ -3199,6 +3223,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; @@ -3824,29 +3876,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 { From 1bda61491831f3e1d7b41206f3347d272bc189b2 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Thu, 9 Sep 2021 16:24:24 +0100 Subject: [PATCH 2/3] fix(CategoryChannel): swap order of parent and options --- src/structures/CategoryChannel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/CategoryChannel.js b/src/structures/CategoryChannel.js index ccd06879f910..c0f3b1194ff1 100644 --- a/src/structures/CategoryChannel.js +++ b/src/structures/CategoryChannel.js @@ -51,8 +51,8 @@ class CategoryChannel extends GuildChannel { */ createChannel(name, options = {}) { return this.guild.channels.create(name, { - parent: this.id, ...options, + parent: this.id, }); } } From 7b23816df3860cf8c2aa237006a974e93e3b1893 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Thu, 9 Sep 2021 17:53:32 +0100 Subject: [PATCH 3/3] fix(CategoryChannel): remove default empty object --- src/structures/CategoryChannel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/CategoryChannel.js b/src/structures/CategoryChannel.js index c0f3b1194ff1..b6b198f1b239 100644 --- a/src/structures/CategoryChannel.js +++ b/src/structures/CategoryChannel.js @@ -49,7 +49,7 @@ class CategoryChannel extends GuildChannel { * @param {CategoryCreateChannelOptions} options Options for creating the new channel * @returns {Promise} */ - createChannel(name, options = {}) { + createChannel(name, options) { return this.guild.channels.create(name, { ...options, parent: this.id,