refactor(GuildChannel): change overwritePermisions to accept an… (#3853)

* refactor(GuildChannel): change overwritePermisions to no longer accept an object

* fix: check for instanceof Collection too
This commit is contained in:
Sugden
2020-02-29 13:19:21 +00:00
committed by GitHub
parent f95df6f7d7
commit e4f567c65e
2 changed files with 15 additions and 11 deletions

View File

@@ -188,24 +188,28 @@ class GuildChannel extends Channel {
/**
* Replaces the permission overwrites in this channel.
* @param {Object} [options] Options
* @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [options.permissionOverwrites]
* @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} 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<GuildChannel>}
* @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);
}
/**

2
typings/index.d.ts vendored
View File

@@ -787,7 +787,7 @@ declare module 'discord.js' {
public equals(channel: GuildChannel): boolean;
public fetchInvites(): Promise<Collection<string, Invite>>;
public lockPermissions(): Promise<this>;
public overwritePermissions(options?: { permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>, reason?: string; }): Promise<this>;
public overwritePermissions(overwrites: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>, reason?: string): Promise<this>;
public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly<Permissions> | null;
public setName(name: string, reason?: string): Promise<this>;
public setParent(channel: GuildChannel | Snowflake, options?: { lockPermissions?: boolean; reason?: string; }): Promise<this>;