Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/client/actions/GuildChannelsPositionUpdate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-depth */
'use strict';

const Action = require('./Action');
Expand All @@ -10,7 +11,26 @@ class GuildChannelsPositionUpdate extends Action {
if (guild) {
for (const partialChannel of data.channels) {
const channel = guild.channels.cache.get(partialChannel.id);
if (channel) channel.rawPosition = partialChannel.position;
if (channel) {
const { position, parent_id, lock_permissions } = partialChannel;
if (position) {
channel.rawPosition = position;
}
if (parent_id) {
const newParent = guild.channels.cache.get(parent_id);
if (newParent) {
channel.parentID = parent_id;
}
}
if (lock_permissions) {
const newParent = guild.channels.cache.get(parent_id);
if (newParent) {
channel.permissionOverwrites = newParent.permissionOverwrites.clone();
} else if (channel.parent) {
channel.permissionOverwrites = channel.parent.permissionOverwrites.clone();
}
}
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,9 @@ class Guild extends Base {
* The data needed for updating a channel's position.
* @typedef {Object} ChannelPosition
* @property {ChannelResolvable} channel Channel to update
* @property {number} position New position for the channel
* @property {number} [position] New position for the channel
* @property {?CategoryChannel|Snowflake} [parent] Parent channel
* @property {boolean} [lockPermissions] If the permissions should be locked to the parent
*/

/**
Expand All @@ -1208,6 +1210,8 @@ class Guild extends Base {
const updatedChannels = channelPositions.map(r => ({
id: this.client.channels.resolveID(r.channel),
position: r.position,
parent_id: r.parent !== null ? this.client.channels.resolveID(r.parent) || undefined : null,
lock_permissions: r.lockPermissions,
}));

return this.client.api
Expand Down
4 changes: 3 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,9 @@ declare module 'discord.js' {

interface ChannelPosition {
channel: ChannelResolvable;
position: number;
position?: number;
parent?: GuildChannel | Snowflake;
lockPermissions?: boolean;
}

type ChannelResolvable = Channel | Snowflake;
Expand Down