This commit is contained in:
Amish Shah
2018-03-05 19:30:21 +00:00
3 changed files with 17 additions and 12 deletions

View File

@@ -29,11 +29,9 @@ class GuildMemberRoleStore extends DataStore {
if (roleOrRoles.includes(null)) { if (roleOrRoles.includes(null)) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true)); 'Array or Collection of Roles or Snowflakes', true));
} else {
for (const role of roleOrRoles) super.set(role.id, role);
} }
const newRoles = [...new Set(roleOrRoles.concat(this.array()))];
return this.set(this, reason); return this.set(newRoles, reason);
} }
/** /**
@@ -71,11 +69,9 @@ class GuildMemberRoleStore extends DataStore {
if (roleOrRoles.includes(null)) { if (roleOrRoles.includes(null)) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true)); 'Array or Collection of Roles or Snowflakes', true));
} else {
for (const role of roleOrRoles) super.remove(role);
} }
const newRoles = this.keyArray().filter(role => !roleOrRoles.includes(role));
return this.set(this, reason); return this.set(newRoles, reason);
} }
/** /**

View File

@@ -132,8 +132,8 @@ class Role extends Base {
/** /**
* Compares this role's position to another role's. * Compares this role's position to another role's.
* @param {RoleResolvable} role Role to compare to this one * @param {RoleResolvable} role Role to compare to this one
* @returns {number} Negative number if the this role's position is lower (other role's is higher), * @returns {number} Negative number if this role's position is lower (other role's is higher),
* positive number if the this one is higher (other's is lower), 0 if equal * positive number if this one is higher (other's is lower), 0 if equal
*/ */
comparePositionTo(role) { comparePositionTo(role) {
role = this.guild.roles.resolve(role); role = this.guild.roles.resolve(role);

View File

@@ -55,6 +55,11 @@ class TextChannel extends GuildChannel {
/** /**
* Fetches all webhooks for the channel. * Fetches all webhooks for the channel.
* @returns {Promise<Collection<Snowflake, Webhook>>} * @returns {Promise<Collection<Snowflake, Webhook>>}
* @example
* // Fetch webhooks
* channel.fetchWebhooks()
* .then(hooks => console.log(`This channel has ${hooks.size} hooks`))
* .catch(console.error);
*/ */
fetchWebhooks() { fetchWebhooks() {
return this.client.api.channels[this.id].webhooks.get().then(data => { return this.client.api.channels[this.id].webhooks.get().then(data => {
@@ -72,8 +77,12 @@ class TextChannel extends GuildChannel {
* @param {string} [options.reason] Reason for creating the webhook * @param {string} [options.reason] Reason for creating the webhook
* @returns {Promise<Webhook>} webhook The created webhook * @returns {Promise<Webhook>} webhook The created webhook
* @example * @example
* channel.createWebhook('Snek', 'https://i.imgur.com/mI8XcpG.jpg') * // Create a webhook for the current channel
* .then(webhook => console.log(`Created webhook ${webhook}`)) * channel.createWebhook('Snek', {
* avatar: 'https://i.imgur.com/mI8XcpG.jpg',
* reason: 'Needed a cool new Webhook'
* })
* .then(console.log)
* .catch(console.error) * .catch(console.error)
*/ */
async createWebhook(name, { avatar, reason } = {}) { async createWebhook(name, { avatar, reason } = {}) {