mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
feat!: add CategoryChannelChildManager (#7320)
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
const DataManager = require('./DataManager');
|
||||
const GuildChannel = require('../structures/GuildChannel');
|
||||
|
||||
/**
|
||||
* Manages API methods for CategoryChannels' children.
|
||||
* @extends {DataManager}
|
||||
*/
|
||||
class CategoryChannelChildManager extends DataManager {
|
||||
constructor(channel) {
|
||||
super(channel.client, GuildChannel);
|
||||
/**
|
||||
* The category channel this manager belongs to
|
||||
* @type {CategoryChannel}
|
||||
*/
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The channels that are a part of this category
|
||||
* @type {Collection<Snowflake, GuildChannel>}
|
||||
* @readonly
|
||||
*/
|
||||
get cache() {
|
||||
return this.guild.channels.cache.filter(c => c.parentId === this.channel.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The guild this manager belongs to
|
||||
* @type {Guild}
|
||||
* @readonly
|
||||
*/
|
||||
get guild() {
|
||||
return this.channel.guild;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for creating a channel using {@link CategoryChannel#createChannel}.
|
||||
* @typedef {Object} CategoryCreateChannelOptions
|
||||
* @property {ChannelType} [type=ChannelType.GuildText] 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 rate limit per user (slowmode) for the new channel in seconds
|
||||
* @property {string} [rtcRegion] The specific region of the new channel.
|
||||
* @property {string} [reason] Reason for creating the new channel
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new channel within this category.
|
||||
* <info>You cannot create a channel of type {@link ChannelType.GuildCategory} 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>}
|
||||
*/
|
||||
create(name, options) {
|
||||
return this.guild.channels.create(name, {
|
||||
...options,
|
||||
parent: this.channel.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CategoryChannelChildManager;
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const GuildChannel = require('./GuildChannel');
|
||||
const CategoryChannelChildManager = require('../managers/CategoryChannelChildManager');
|
||||
|
||||
/**
|
||||
* Represents a guild category channel on Discord.
|
||||
@@ -8,12 +9,12 @@ const GuildChannel = require('./GuildChannel');
|
||||
*/
|
||||
class CategoryChannel extends GuildChannel {
|
||||
/**
|
||||
* Channels that are a part of this category
|
||||
* @type {Collection<Snowflake, GuildChannel>}
|
||||
* A manager of the channels belonging to this category
|
||||
* @type {CategoryChannelChildManager}
|
||||
* @readonly
|
||||
*/
|
||||
get children() {
|
||||
return this.guild.channels.cache.filter(c => c.parentId === this.id);
|
||||
return new CategoryChannelChildManager(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,37 +27,6 @@ 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} [type=ChannelType.GuildText] 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 rate limit per user (slowmode) for the new channel in seconds
|
||||
* @property {string} [rtcRegion] The specific region of the new channel.
|
||||
* @property {string} [reason] Reason for creating the new channel
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new channel within this category.
|
||||
* <info>You cannot create a channel of type {@link ChannelType.GuildCategory} 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) {
|
||||
return this.guild.channels.create(name, {
|
||||
...options,
|
||||
parent: this.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CategoryChannel;
|
||||
|
||||
36
packages/discord.js/typings/index.d.ts
vendored
36
packages/discord.js/typings/index.d.ts
vendored
@@ -526,19 +526,8 @@ export type CategoryChannelType = Exclude<
|
||||
>;
|
||||
|
||||
export class CategoryChannel extends GuildChannel {
|
||||
public readonly children: Collection<Snowflake, Exclude<NonThreadGuildBasedChannel, CategoryChannel>>;
|
||||
public readonly children: CategoryChannelChildManager;
|
||||
public type: ChannelType.GuildCategory;
|
||||
|
||||
public createChannel<T extends Exclude<CategoryChannelType, ChannelType.GuildStore>>(
|
||||
name: string,
|
||||
options: CategoryCreateChannelOptions & { type: T },
|
||||
): Promise<MappedChannelCategoryTypes[T]>;
|
||||
/** @deprecated See [Self-serve Game Selling Deprecation](https://support-dev.discord.com/hc/en-us/articles/4414590563479) for more information */
|
||||
public createChannel(
|
||||
name: string,
|
||||
options: CategoryCreateChannelOptions & { type: ChannelType.GuildStore },
|
||||
): Promise<StoreChannel>;
|
||||
public createChannel(name: string, options?: CategoryCreateChannelOptions): Promise<TextChannel>;
|
||||
}
|
||||
|
||||
export type CategoryChannelResolvable = Snowflake | CategoryChannel;
|
||||
@@ -2792,6 +2781,27 @@ export class BaseGuildEmojiManager extends CachedManager<Snowflake, GuildEmoji,
|
||||
public resolveIdentifier(emoji: EmojiIdentifierResolvable): string | null;
|
||||
}
|
||||
|
||||
export class CategoryChannelChildManager extends DataManager<
|
||||
Snowflake,
|
||||
NonCategoryGuildBasedChannel,
|
||||
GuildChannelResolvable
|
||||
> {
|
||||
private constructor(channel: CategoryChannel);
|
||||
|
||||
public channel: CategoryChannel;
|
||||
public readonly guild: Guild;
|
||||
public create<T extends Exclude<CategoryChannelType, ChannelType.GuildStore>>(
|
||||
name: string,
|
||||
options: CategoryCreateChannelOptions & { type: T },
|
||||
): Promise<MappedChannelCategoryTypes[T]>;
|
||||
/** @deprecated See [Self-serve Game Selling Deprecation](https://support-dev.discord.com/hc/en-us/articles/4414590563479) for more information */
|
||||
public create(
|
||||
name: string,
|
||||
options: CategoryCreateChannelOptions & { type: ChannelType.GuildStore },
|
||||
): Promise<StoreChannel>;
|
||||
public create(name: string, options?: CategoryCreateChannelOptions): Promise<TextChannel>;
|
||||
}
|
||||
|
||||
export class ChannelManager extends CachedManager<Snowflake, AnyChannel, ChannelResolvable> {
|
||||
private constructor(client: Client, iterable: Iterable<RawChannelData>);
|
||||
public fetch(id: Snowflake, options?: FetchChannelOptions): Promise<AnyChannel | null>;
|
||||
@@ -4958,6 +4968,8 @@ export type VoiceBasedChannel = Extract<AnyChannel, { bitrate: number }>;
|
||||
|
||||
export type GuildBasedChannel = Extract<AnyChannel, { guild: Guild }>;
|
||||
|
||||
export type NonCategoryGuildBasedChannel = Exclude<GuildBasedChannel, CategoryChannel>;
|
||||
|
||||
export type NonThreadGuildBasedChannel = Exclude<GuildBasedChannel, ThreadChannel>;
|
||||
|
||||
export type GuildTextBasedChannel = Extract<GuildBasedChannel, TextBasedChannel>;
|
||||
|
||||
@@ -101,6 +101,7 @@ import {
|
||||
Events,
|
||||
ShardEvents,
|
||||
Status,
|
||||
CategoryChannelChildManager,
|
||||
} from '.';
|
||||
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
||||
import { Embed } from '@discordjs/builders';
|
||||
@@ -824,7 +825,7 @@ expectType<Message | null>(newsChannel.lastMessage);
|
||||
expectType<Message | null>(textChannel.lastMessage);
|
||||
|
||||
expectDeprecated(storeChannel.clone());
|
||||
expectDeprecated(categoryChannel.createChannel('Store', { type: ChannelType.GuildStore }));
|
||||
expectDeprecated(categoryChannelChildManager.create('Store', { type: ChannelType.GuildStore }));
|
||||
expectDeprecated(guild.channels.create('Store', { type: ChannelType.GuildStore }));
|
||||
|
||||
notPropertyOf(user, 'lastMessage');
|
||||
@@ -904,15 +905,15 @@ expectType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationC
|
||||
expectType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationCommandManager.fetch(undefined, {}));
|
||||
expectType<Promise<ApplicationCommand>>(guildApplicationCommandManager.fetch('0'));
|
||||
|
||||
declare const categoryChannel: CategoryChannel;
|
||||
declare const categoryChannelChildManager: CategoryChannelChildManager;
|
||||
{
|
||||
expectType<Promise<VoiceChannel>>(categoryChannel.createChannel('name', { type: ChannelType.GuildVoice }));
|
||||
expectType<Promise<TextChannel>>(categoryChannel.createChannel('name', { type: ChannelType.GuildText }));
|
||||
expectType<Promise<NewsChannel>>(categoryChannel.createChannel('name', { type: ChannelType.GuildNews }));
|
||||
expectDeprecated(categoryChannel.createChannel('name', { type: ChannelType.GuildStore }));
|
||||
expectType<Promise<StageChannel>>(categoryChannel.createChannel('name', { type: ChannelType.GuildStageVoice }));
|
||||
expectType<Promise<TextChannel>>(categoryChannel.createChannel('name', {}));
|
||||
expectType<Promise<TextChannel>>(categoryChannel.createChannel('name'));
|
||||
expectType<Promise<VoiceChannel>>(categoryChannelChildManager.create('name', { type: ChannelType.GuildVoice }));
|
||||
expectType<Promise<TextChannel>>(categoryChannelChildManager.create('name', { type: ChannelType.GuildText }));
|
||||
expectType<Promise<NewsChannel>>(categoryChannelChildManager.create('name', { type: ChannelType.GuildNews }));
|
||||
expectDeprecated(categoryChannelChildManager.create('name', { type: ChannelType.GuildStore }));
|
||||
expectType<Promise<StageChannel>>(categoryChannelChildManager.create('name', { type: ChannelType.GuildStageVoice }));
|
||||
expectType<Promise<TextChannel>>(categoryChannelChildManager.create('name', {}));
|
||||
expectType<Promise<TextChannel>>(categoryChannelChildManager.create('name'));
|
||||
}
|
||||
|
||||
declare const guildChannelManager: GuildChannelManager;
|
||||
|
||||
Reference in New Issue
Block a user