From e4f567c65ef3dfd1f0ae7ddc40a862445549f9d4 Mon Sep 17 00:00:00 2001 From: Sugden <28943913+NotSugden@users.noreply.github.com> Date: Sat, 29 Feb 2020 13:19:21 +0000 Subject: [PATCH] =?UTF-8?q?refactor(GuildChannel):=20change=20overwritePer?= =?UTF-8?q?misions=20to=20accept=20an=E2=80=A6=20(#3853)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor(GuildChannel): change overwritePermisions to no longer accept an object * fix: check for instanceof Collection too --- src/structures/GuildChannel.js | 24 ++++++++++++++---------- typings/index.d.ts | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index d80f5b24f..349dcad10 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -188,24 +188,28 @@ class GuildChannel extends Channel { /** * Replaces the permission overwrites in this channel. - * @param {Object} [options] Options - * @param {OverwriteResolvable[]|Collection} [options.permissionOverwrites] + * @param {OverwriteResolvable[]|Collection} overwrites * Permission overwrites the channel gets updated with - * @param {string} [options.reason] Reason for updating the channel overwrites + * @param {string} [reason] Reason for updating the channel overwrites * @returns {Promise} * @example - * channel.overwritePermissions({ - * permissionOverwrites: [ + * channel.overwritePermissions([ * { * id: message.author.id, * deny: ['VIEW_CHANNEL'], * }, - * ], - * reason: 'Needed to change permissions' - * }); + * ], 'Needed to change permissions'); */ - overwritePermissions(options = {}) { - return this.edit(options).then(() => this); + overwritePermissions(overwrites, reason) { + if (!Array.isArray(overwrites) && !(overwrites instanceof Collection)) { + return Promise.reject(new TypeError( + 'INVALID_TYPE', + 'overwrites', + 'Array or Collection of Permission Overwrites', + true, + )); + } + return this.edit({ permissionOverwrites: overwrites, reason }).then(() => this); } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 42b05a312..659a1b89c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -787,7 +787,7 @@ declare module 'discord.js' { public equals(channel: GuildChannel): boolean; public fetchInvites(): Promise>; public lockPermissions(): Promise; - public overwritePermissions(options?: { permissionOverwrites?: OverwriteResolvable[] | Collection, reason?: string; }): Promise; + public overwritePermissions(overwrites: OverwriteResolvable[] | Collection, reason?: string): Promise; public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly | null; public setName(name: string, reason?: string): Promise; public setParent(channel: GuildChannel | Snowflake, options?: { lockPermissions?: boolean; reason?: string; }): Promise;