mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
refactor: consistently use permissionOverwrites over overwrites (#2886)
This commit is contained in:
@@ -31,7 +31,7 @@ class GuildChannelStore extends DataStore {
|
|||||||
* @param {number} [options.bitrate] Bitrate of the new channel in bits (only voice)
|
* @param {number} [options.bitrate] Bitrate of the new channel in bits (only voice)
|
||||||
* @param {number} [options.userLimit] Maximum amount of users allowed in the new channel (only voice)
|
* @param {number} [options.userLimit] Maximum amount of users allowed in the new channel (only voice)
|
||||||
* @param {ChannelResolvable} [options.parent] Parent of the new channel
|
* @param {ChannelResolvable} [options.parent] Parent of the new channel
|
||||||
* @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [options.overwrites]
|
* @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [options.permissionOverwrites]
|
||||||
* Permission overwrites of the new channel
|
* Permission overwrites of the new channel
|
||||||
* @param {number} [options.rateLimitPerUser] The ratelimit per user for the channel
|
* @param {number} [options.rateLimitPerUser] The ratelimit per user for the channel
|
||||||
* @param {string} [options.reason] Reason for creating the channel
|
* @param {string} [options.reason] Reason for creating the channel
|
||||||
@@ -42,10 +42,10 @@ class GuildChannelStore extends DataStore {
|
|||||||
* .then(console.log)
|
* .then(console.log)
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
* @example
|
* @example
|
||||||
* // Create a new channel with overwrites
|
* // Create a new channel with permission overwrites
|
||||||
* guild.channels.create('new-voice', {
|
* guild.channels.create('new-voice', {
|
||||||
* type: 'voice',
|
* type: 'voice',
|
||||||
* overwrites: [
|
* permissionOverwrites: [
|
||||||
* {
|
* {
|
||||||
* id: message.author.id,
|
* id: message.author.id,
|
||||||
* deny: ['VIEW_CHANNEL'],
|
* deny: ['VIEW_CHANNEL'],
|
||||||
@@ -53,8 +53,12 @@ class GuildChannelStore extends DataStore {
|
|||||||
* ],
|
* ],
|
||||||
* })
|
* })
|
||||||
*/
|
*/
|
||||||
async create(name, { type, topic, nsfw, bitrate, userLimit, parent, overwrites, rateLimitPerUser, reason } = {}) {
|
async create(name, options = {}) {
|
||||||
|
let { type, topic, nsfw, bitrate, userLimit, parent, permissionOverwrites, rateLimitPerUser, reason } = options;
|
||||||
if (parent) parent = this.client.channels.resolveID(parent);
|
if (parent) parent = this.client.channels.resolveID(parent);
|
||||||
|
if (permissionOverwrites) {
|
||||||
|
permissionOverwrites = permissionOverwrites.map(o => PermissionOverwrites.resolve(o, this.guild));
|
||||||
|
}
|
||||||
|
|
||||||
const data = await this.client.api.guilds(this.guild.id).channels.post({
|
const data = await this.client.api.guilds(this.guild.id).channels.post({
|
||||||
data: {
|
data: {
|
||||||
@@ -65,7 +69,7 @@ class GuildChannelStore extends DataStore {
|
|||||||
bitrate,
|
bitrate,
|
||||||
user_limit: userLimit,
|
user_limit: userLimit,
|
||||||
parent_id: parent,
|
parent_id: parent,
|
||||||
permission_overwrites: overwrites && overwrites.map(o => PermissionOverwrites.resolve(o, this.guild)),
|
permission_overwrites: permissionOverwrites,
|
||||||
rate_limit_per_user: rateLimitPerUser,
|
rate_limit_per_user: rateLimitPerUser,
|
||||||
},
|
},
|
||||||
reason,
|
reason,
|
||||||
|
|||||||
@@ -178,13 +178,13 @@ class GuildChannel extends Channel {
|
|||||||
/**
|
/**
|
||||||
* Replaces the permission overwrites in this channel.
|
* Replaces the permission overwrites in this channel.
|
||||||
* @param {Object} [options] Options
|
* @param {Object} [options] Options
|
||||||
* @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [options.overwrites]
|
* @param {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [options.permissionOverwrites]
|
||||||
* Permission overwrites the channel gets updated with
|
* Permission overwrites the channel gets updated with
|
||||||
* @param {string} [options.reason] Reason for updating the channel overwrites
|
* @param {string} [options.reason] Reason for updating the channel overwrites
|
||||||
* @returns {Promise<GuildChannel>}
|
* @returns {Promise<GuildChannel>}
|
||||||
* @example
|
* @example
|
||||||
* channel.overwritePermissions({
|
* channel.overwritePermissions({
|
||||||
* overwrites: [
|
* permissionOverwrites: [
|
||||||
* {
|
* {
|
||||||
* id: message.author.id,
|
* id: message.author.id,
|
||||||
* deny: ['VIEW_CHANNEL'],
|
* deny: ['VIEW_CHANNEL'],
|
||||||
@@ -193,9 +193,8 @@ class GuildChannel extends Channel {
|
|||||||
* reason: 'Needed to change permissions'
|
* reason: 'Needed to change permissions'
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
overwritePermissions({ overwrites, reason } = {}) {
|
overwritePermissions(options = {}) {
|
||||||
return this.edit({ permissionOverwrites: overwrites, reason })
|
return this.edit(options).then(() => this);
|
||||||
.then(() => this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -465,10 +464,11 @@ class GuildChannel extends Channel {
|
|||||||
*/
|
*/
|
||||||
clone(options = {}) {
|
clone(options = {}) {
|
||||||
if (typeof options.withPermissions === 'undefined') options.withPermissions = true;
|
if (typeof options.withPermissions === 'undefined') options.withPermissions = true;
|
||||||
|
if (typeof options.withTopic === 'undefined') options.withTopic = true;
|
||||||
Util.mergeDefault({
|
Util.mergeDefault({
|
||||||
name: this.name,
|
name: this.name,
|
||||||
overwrites: options.withPermissions ? this.permissionOverwrites : [],
|
permissionOverwrites: options.withPermissions ? this.permissionOverwrites : [],
|
||||||
withTopic: true,
|
topic: options.withTopic ? this.topic : undefined,
|
||||||
nsfw: this.nsfw,
|
nsfw: this.nsfw,
|
||||||
parent: this.parent,
|
parent: this.parent,
|
||||||
bitrate: this.bitrate,
|
bitrate: this.bitrate,
|
||||||
@@ -476,8 +476,7 @@ class GuildChannel extends Channel {
|
|||||||
reason: null,
|
reason: null,
|
||||||
}, options);
|
}, options);
|
||||||
options.type = this.type;
|
options.type = this.type;
|
||||||
return this.guild.channels.create(options.name, options)
|
return this.guild.channels.create(options.name, options);
|
||||||
.then(channel => options.withTopic ? channel.setTopic(this.topic) : channel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
4
typings/index.d.ts
vendored
4
typings/index.d.ts
vendored
@@ -533,7 +533,7 @@ declare module 'discord.js' {
|
|||||||
public equals(channel: GuildChannel): boolean;
|
public equals(channel: GuildChannel): boolean;
|
||||||
public fetchInvites(): Promise<Collection<string, Invite>>;
|
public fetchInvites(): Promise<Collection<string, Invite>>;
|
||||||
public lockPermissions(): Promise<GuildChannel>;
|
public lockPermissions(): Promise<GuildChannel>;
|
||||||
public overwritePermissions(options?: { overwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>, reason?: string }): Promise<GuildChannel>;
|
public overwritePermissions(options?: { permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>, reason?: string }): Promise<GuildChannel>;
|
||||||
public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly<Permissions> | null;
|
public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly<Permissions> | null;
|
||||||
public setName(name: string, reason?: string): Promise<GuildChannel>;
|
public setName(name: string, reason?: string): Promise<GuildChannel>;
|
||||||
public setParent(channel: GuildChannel | Snowflake, options?: { lockPermissions?: boolean, reason?: string }): Promise<GuildChannel>;
|
public setParent(channel: GuildChannel | Snowflake, options?: { lockPermissions?: boolean, reason?: string }): Promise<GuildChannel>;
|
||||||
@@ -1757,7 +1757,7 @@ declare module 'discord.js' {
|
|||||||
bitrate?: number;
|
bitrate?: number;
|
||||||
userLimit?: number;
|
userLimit?: number;
|
||||||
parent?: ChannelResolvable;
|
parent?: ChannelResolvable;
|
||||||
overwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
||||||
rateLimitPerUser?: number;
|
rateLimitPerUser?: number;
|
||||||
reason?: string
|
reason?: string
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user