-
Notifications
You must be signed in to change notification settings - Fork 416
/
CategoryChannel.js
44 lines (40 loc) · 1.54 KB
/
CategoryChannel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
const Collection = require("../util/Collection");
const GuildChannel = require("./GuildChannel");
/**
* Represents a guild category channel
* @extends GuildChannel
* @prop {String} id The ID of the channel
* @prop {String} mention A string that mentions the channel
* @prop {Number} type The type of the channel
* @prop {Guild} guild The guild that owns the channel
* @prop {String?} parentID The ID of the category this channel belongs to
* @prop {String} name The name of the channel
* @prop {Number} position The position of the channel
* @prop {Boolean} nsfw Whether the channel is an NSFW channel or not
* @prop {Collection<PermissionOverwrite>} permissionOverwrites Collection of PermissionOverwrites in this channel
* @prop {Collection<GuildChannel>} channels A collection of guild channels that are part of this category
*/
class CategoryChannel extends GuildChannel {
get channels() {
const channels = new Collection(GuildChannel);
if(this.guild && this.guild.channels) {
for(const channel of this.guild.channels.values()) {
if(channel.parentID === this.id) {
channels.add(channel);
}
}
}
return channels;
}
toJSON() {
const base = super.toJSON(true);
for(const prop of ["channels"]) {
if(this[prop] !== undefined) {
base[prop] = this[prop] && this[prop].toJSON ? this[prop].toJSON() : this[prop];
}
}
return base;
}
}
module.exports = CategoryChannel;