Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CategoryChannel): add createChannel shortcut method #6614

Merged
merged 3 commits into from Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/managers/GuildChannelManager.js
Expand Up @@ -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<Snowflake, OverwriteResolvable>} [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
*/

/**
Expand Down
29 changes: 29 additions & 0 deletions src/structures/CategoryChannel.js
Expand Up @@ -26,6 +26,35 @@ class CategoryChannel extends GuildChannel {
* @param {SetParentOptions} [options={}] The options for setting the parent
* @returns {Promise<GuildChannel>}
*/

/**
* 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<Snowflake, OverwriteResolvable>} [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.
* <info>You cannot create a channel of type `GUILD_CATEGORY` inside a CategoryChannel.</info>
* @param {string} name The name of the new channel
* @param {CategoryCreateChannelOptions} options Options for creating the new channel
* @returns {Promise<GuildChannel>}
*/
createChannel(name, options = {}) {
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
return this.guild.channels.create(name, {
...options,
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
parent: this.id,
});
}
}

module.exports = CategoryChannel;
66 changes: 56 additions & 10 deletions typings/index.d.ts
Expand Up @@ -387,6 +387,30 @@ export class ButtonInteraction extends MessageComponentInteraction {
export class CategoryChannel extends GuildChannel {
public readonly children: Collection<Snowflake, GuildChannel>;
public type: 'GUILD_CATEGORY';
public createChannel(
name: string,
options: CategoryCreateChannelOptions & { type: 'GUILD_VOICE' },
): Promise<VoiceChannel>;
public createChannel(
name: string,
options?: CategoryCreateChannelOptions & { type?: 'GUILD_TEXT' },
): Promise<TextChannel>;
public createChannel(
name: string,
options: CategoryCreateChannelOptions & { type: 'GUILD_NEWS' },
): Promise<NewsChannel>;
public createChannel(
name: string,
options: CategoryCreateChannelOptions & { type: 'GUILD_STORE' },
): Promise<StoreChannel>;
public createChannel(
name: string,
options: CategoryCreateChannelOptions & { type: 'GUILD_STAGE_VOICE' },
): Promise<StageChannel>;
public createChannel(
name: string,
options: CategoryCreateChannelOptions,
): Promise<TextChannel | VoiceChannel | NewsChannel | StoreChannel | StageChannel>;
}

export type CategoryChannelResolvable = Snowflake | CategoryChannel;
Expand Down Expand Up @@ -3199,6 +3223,34 @@ export type CacheWithLimitsOptions = {
: never;
};

export interface CategoryCreateChannelOptions {
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
topic?: string;
type?: Exclude<
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -3824,29 +3876,23 @@ export interface GuildChannelOverwriteOptions {

export type GuildChannelResolvable = Snowflake | GuildChannel | ThreadChannel;

export interface GuildChannelCreateOptions {
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
topic?: string;
export interface GuildChannelCreateOptions extends Omit<CategoryCreateChannelOptions, 'type'> {
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 {
Expand Down