diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index e21f065d6..66efd8c2b 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -275,12 +275,21 @@ class GuildChannel extends Channel { * .then(c => console.log(`Edited channel ${c}`)) * .catch(console.error); */ - edit(data, reason) { + async edit(data, reason) { + if (typeof data.position !== 'undefined') { + await Util.setPosition(this, data.position, false, + this.guild._sortedChannels(this), this.client.api.guilds(this.guild.id).channels, reason) + .then(updatedChannels => { + this.client.actions.GuildChannelsPositionUpdate.handle({ + guild_id: this.guild.id, + channels: updatedChannels, + }); + }); + } return this.client.api.channels(this.id).patch({ data: { name: (data.name || this.name).trim(), topic: data.topic, - position: typeof data.position === 'number' ? data.position : this.rawPosition, bitrate: data.bitrate || (this.bitrate ? this.bitrate * 1000 : undefined), user_limit: data.userLimit != null ? data.userLimit : this.userLimit, // eslint-disable-line eqeqeq parent_id: data.parentID, diff --git a/src/structures/Role.js b/src/structures/Role.js index 3a2d23319..eb60185db 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -165,15 +165,24 @@ class Role extends Base { * .then(r => console.log(`Edited role ${r}`)) * .catch(console.error); */ - edit(data, reason) { + async edit(data, reason) { if (data.permissions) data.permissions = Permissions.resolve(data.permissions); else data.permissions = this.permissions.bitfield; + if (typeof data.position !== 'undefined') { + await Util.setPosition(this, data.position, false, this.guild._sortedRoles(), + this.client.api.guilds(this.guild.id).roles, reason) + .then(updatedRoles => { + this.client.actions.GuildRolesPositionUpdate.handle({ + guild_id: this.guild.id, + roles: updatedRoles, + }); + }); + } return this.client.api.guilds[this.guild.id].roles[this.id].patch({ data: { name: data.name || this.name, color: Util.resolveColor(data.color || this.color), hoist: typeof data.hoist !== 'undefined' ? data.hoist : this.hoist, - position: typeof data.position !== 'undefined' ? data.position : this.position, permissions: data.permissions, mentionable: typeof data.mentionable !== 'undefined' ? data.mentionable : this.mentionable, },