mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
Improved Guild#createChannel, added RoleResolvable and fixed a bit of Emoji stuff (#1754)
* Made creating channels with overwrites nicer and added ClientDataResolver#resolveRole * Renamed ChannelPermissionOverwrites to ChannelCreationOverwrites * Added RoleResolvables everywhere possible * Fixed Emoji#setName resetting restricted roles and Emoji#equals Which will lead to emojis not to update when roles are being added removed.
This commit is contained in:
@@ -106,7 +106,7 @@ class Emoji {
|
||||
* Data for editing an emoji.
|
||||
* @typedef {Object} EmojiEditData
|
||||
* @property {string} [name] The name of the emoji
|
||||
* @property {Collection<Snowflake, Role>|Array<Snowflake|Role>} [roles] Roles to restrict emoji to
|
||||
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] Roles to restrict emoji to
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -124,7 +124,7 @@ class Emoji {
|
||||
return this.client.api.guilds(this.guild.id).emojis(this.id)
|
||||
.patch({ data: {
|
||||
name: data.name,
|
||||
roles: data.roles ? data.roles.map(r => r.id ? r.id : r) : [],
|
||||
roles: data.roles ? data.roles.map(r => r.id ? r.id : r) : undefined,
|
||||
}, reason })
|
||||
.then(() => this);
|
||||
}
|
||||
@@ -150,13 +150,18 @@ class Emoji {
|
||||
|
||||
/**
|
||||
* Add multiple roles to the list of roles that can use this emoji.
|
||||
* @param {Role[]} roles Roles to add
|
||||
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles Roles to add
|
||||
* @returns {Promise<Emoji>}
|
||||
*/
|
||||
addRestrictedRoles(roles) {
|
||||
const newRoles = new Collection(this.roles);
|
||||
for (const role of roles) {
|
||||
if (this.guild.roles.has(role.id)) newRoles.set(role.id, role);
|
||||
for (let role of roles instanceof Collection ? roles.values() : roles) {
|
||||
role = this.client.resolver.resolveRole(this.guild, role);
|
||||
if (!role) {
|
||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
||||
'Array or Collection of Roles or Snowflakes', true));
|
||||
}
|
||||
newRoles.set(role.id, role);
|
||||
}
|
||||
return this.edit({ roles: newRoles });
|
||||
}
|
||||
@@ -172,12 +177,17 @@ class Emoji {
|
||||
|
||||
/**
|
||||
* Remove multiple roles from the list of roles that can use this emoji.
|
||||
* @param {Role[]} roles Roles to remove
|
||||
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles Roles to remove
|
||||
* @returns {Promise<Emoji>}
|
||||
*/
|
||||
removeRestrictedRoles(roles) {
|
||||
const newRoles = new Collection(this.roles);
|
||||
for (const role of roles) {
|
||||
for (let role of roles instanceof Collection ? roles.values() : roles) {
|
||||
role = this.client.resolver.resolveRole(this.guild, role);
|
||||
if (!role) {
|
||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
||||
'Array or Collection of Roles or Snowflakes', true));
|
||||
}
|
||||
if (newRoles.has(role.id)) newRoles.delete(role.id);
|
||||
}
|
||||
return this.edit({ roles: newRoles });
|
||||
@@ -206,12 +216,14 @@ class Emoji {
|
||||
other.id === this.id &&
|
||||
other.name === this.name &&
|
||||
other.managed === this.managed &&
|
||||
other.requiresColons === this.requiresColons
|
||||
other.requiresColons === this.requiresColons &&
|
||||
other._roles === this._roles
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
other.id === this.id &&
|
||||
other.name === this.name
|
||||
other.name === this.name &&
|
||||
other._roles === this._roles
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user