mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
feature(CategoryChannel): backport (#2117)
* feature(CategoryChannel): backport fix no * ???? * bad ternary
This commit is contained in:
committed by
Schuyler Cebulskie
parent
b274dba6ec
commit
cce2480bb5
@@ -2,6 +2,7 @@ const Constants = require('../util/Constants');
|
||||
const Util = require('../util/Util');
|
||||
const Guild = require('../structures/Guild');
|
||||
const User = require('../structures/User');
|
||||
const CategoryChannel = require('../structures/CategoryChannel');
|
||||
const DMChannel = require('../structures/DMChannel');
|
||||
const Emoji = require('../structures/Emoji');
|
||||
const TextChannel = require('../structures/TextChannel');
|
||||
@@ -61,6 +62,9 @@ class ClientDataManager {
|
||||
} else if (data.type === Constants.ChannelTypes.VOICE) {
|
||||
channel = new VoiceChannel(guild, data);
|
||||
guild.channels.set(channel.id, channel);
|
||||
} else if (data.type === Constants.ChannelTypes.CATEGORY) {
|
||||
channel = new CategoryChannel(guild, data);
|
||||
guild.channels.set(channel.id, channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ class RESTMethods {
|
||||
if (overwrites instanceof Collection) overwrites = overwrites.array();
|
||||
return this.rest.makeRequest('post', Endpoints.Guild(guild).channels, true, {
|
||||
name: channelName,
|
||||
type: channelType,
|
||||
type: Constants.ChannelTypes[channelType.toUpperCase()],
|
||||
permission_overwrites: overwrites,
|
||||
}, undefined, reason).then(data => this.client.actions.ChannelCreate.handle(data).channel);
|
||||
}
|
||||
@@ -320,6 +320,7 @@ class RESTMethods {
|
||||
data.position = _data.position || channel.position;
|
||||
data.bitrate = _data.bitrate || channel.bitrate;
|
||||
data.user_limit = _data.userLimit || channel.userLimit;
|
||||
data.parent_id = _data.parent || (channel.parent ? channel.parent.id : undefined);
|
||||
return this.rest.makeRequest('patch', Endpoints.Channel(channel), true, data, undefined, reason).then(newData =>
|
||||
this.client.actions.ChannelUpdate.handle(newData).updated
|
||||
);
|
||||
|
||||
18
src/structures/CategoryChannel.js
Normal file
18
src/structures/CategoryChannel.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const GuildChannel = require('./GuildChannel');
|
||||
|
||||
/**
|
||||
* Represents a guild category channel on Discord.
|
||||
* @extends {GuildChannel}
|
||||
*/
|
||||
class CategoryChannel extends GuildChannel {
|
||||
/**
|
||||
* The channels that are part of this category
|
||||
* @type {?Collection<Snowflake, GuildChannel>}
|
||||
* @readonly
|
||||
*/
|
||||
get children() {
|
||||
return this.guild.channels.filter(c => c.parentID === this.id);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CategoryChannel;
|
||||
@@ -876,7 +876,7 @@ class Guild {
|
||||
/**
|
||||
* Creates a new channel in the guild.
|
||||
* @param {string} name The name of the new channel
|
||||
* @param {string} type The type of the new channel, either `text` or `voice`
|
||||
* @param {string} type The type of the new channel, either `text` or `voice` or `category`
|
||||
* @param {Array<PermissionOverwrites|Object>} [overwrites] Permission overwrites to apply to the new channel
|
||||
* @param {string} [reason] Reason for creating this channel
|
||||
* @returns {Promise<TextChannel|VoiceChannel>}
|
||||
|
||||
@@ -35,6 +35,12 @@ class GuildChannel extends Channel {
|
||||
*/
|
||||
this.position = data.position;
|
||||
|
||||
/**
|
||||
* The ID of the category parent of this channel
|
||||
* @type {?Snowflake}
|
||||
*/
|
||||
this.parentID = data.parent_id;
|
||||
|
||||
/**
|
||||
* A map of permission overwrites in this channel for roles and users
|
||||
* @type {Collection<Snowflake, PermissionOverwrites>}
|
||||
@@ -57,6 +63,15 @@ class GuildChannel extends Channel {
|
||||
return sorted.array().indexOf(sorted.get(this.id));
|
||||
}
|
||||
|
||||
/**
|
||||
* The category parent of this channel
|
||||
* @type {?CategoryChannel}
|
||||
* @readonly
|
||||
*/
|
||||
get parent() {
|
||||
return this.guild.channels.get(this.parentID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the overall set of permissions for a user in this channel, taking into account roles and permission
|
||||
* overwrites.
|
||||
@@ -213,7 +228,7 @@ class GuildChannel extends Channel {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(data, reason) {
|
||||
return this.client.rest.methods.updateChannel(this, data, reason);
|
||||
return this.client.rest.methods.updateChannel(this, data, reason).then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,7 +258,18 @@ class GuildChannel extends Channel {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setPosition(position, relative) {
|
||||
return this.guild.setChannelPosition(this, position, relative).then(() => this);
|
||||
return this.guild.setChannelPosition(this, position, relative);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new parent for the guild channel.
|
||||
* @param {GuildChannel|SnowFlake} parent The new parent for the guild channel
|
||||
* @param {string} [reason] Reason for changing the guild channel's parent
|
||||
* @returns {Promise<GuildChannel>}
|
||||
*/
|
||||
setParent(parent, reason) {
|
||||
parent = this.client.resolver.resolveChannelID(parent);
|
||||
return this.edit({ parent }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,7 +124,7 @@ class OAuth2Application {
|
||||
|
||||
/**
|
||||
* Reset the app's secret and bot token.
|
||||
* <warn>This is only available when using a user account.</warn>
|
||||
* <warn>This is only available when using a user account.</warn>
|
||||
* @returns {OAuth2Application}
|
||||
*/
|
||||
reset() {
|
||||
|
||||
@@ -275,6 +275,7 @@ exports.ChannelTypes = {
|
||||
DM: 1,
|
||||
VOICE: 2,
|
||||
GROUP_DM: 3,
|
||||
CATEGORY: 4,
|
||||
};
|
||||
|
||||
exports.OPCodes = {
|
||||
|
||||
Reference in New Issue
Block a user