Adding reason parameter to GuildMember's methods (#1710)

* Added reason parameter to GuildMember's methods

* Reason parameters are optional
This commit is contained in:
SpaceEEC
2017-07-26 10:04:25 +02:00
committed by Crawl
parent 57b6980313
commit 278fe74a58

View File

@@ -356,19 +356,21 @@ class GuildMember {
/** /**
* Mute/unmute a user. * Mute/unmute a user.
* @param {boolean} mute Whether or not the member should be muted * @param {boolean} mute Whether or not the member should be muted
* @param {string} [reason] Reason for muting or unmuting
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
*/ */
setMute(mute) { setMute(mute, reason) {
return this.edit({ mute }); return this.edit({ mute }, reason);
} }
/** /**
* Deafen/undeafen a user. * Deafen/undeafen a user.
* @param {boolean} deaf Whether or not the member should be deafened * @param {boolean} deaf Whether or not the member should be deafened
* @param {string} [reason] Reason for deafening or undeafening
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
*/ */
setDeaf(deaf) { setDeaf(deaf, reason) {
return this.edit({ deaf }); return this.edit({ deaf }, reason);
} }
/** /**
@@ -383,32 +385,35 @@ class GuildMember {
/** /**
* Sets the roles applied to the member. * Sets the roles applied to the member.
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to apply * @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to apply
* @param {string} [reason] Reason for applying the roles
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
*/ */
setRoles(roles) { setRoles(roles, reason) {
return this.edit({ roles }); return this.edit({ roles }, reason);
} }
/** /**
* Adds a single role to the member. * Adds a single role to the member.
* @param {Role|Snowflake} role The role or ID of the role to add * @param {Role|Snowflake} role The role or ID of the role to add
* @param {string} [reason] Reason for adding the role
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
*/ */
addRole(role) { addRole(role, reason) {
if (!(role instanceof Role)) role = this.guild.roles.get(role); if (!(role instanceof Role)) role = this.guild.roles.get(role);
if (!role) return Promise.reject(new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake')); if (!role) return Promise.reject(new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake'));
if (this._roles.includes(role.id)) return Promise.resolve(this); if (this._roles.includes(role.id)) return Promise.resolve(this);
return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id) return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id)
.put() .put({ reason })
.then(() => this); .then(() => this);
} }
/** /**
* Adds multiple roles to the member. * Adds multiple roles to the member.
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to add * @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to add
* @param {string} [reason] Reason for adding the roles
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
*/ */
addRoles(roles) { addRoles(roles, reason) {
let allRoles; let allRoles;
if (roles instanceof Collection) { if (roles instanceof Collection) {
allRoles = this._roles.slice(); allRoles = this._roles.slice();
@@ -416,28 +421,30 @@ class GuildMember {
} else { } else {
allRoles = this._roles.concat(roles.map(r => r.id ? r.id : r)); allRoles = this._roles.concat(roles.map(r => r.id ? r.id : r));
} }
return this.edit({ roles: allRoles }); return this.edit({ roles: allRoles }, reason);
} }
/** /**
* Removes a single role from the member. * Removes a single role from the member.
* @param {Role|Snowflake} role The role or ID of the role to remove * @param {Role|Snowflake} role The role or ID of the role to remove
* @param {string} [reason] Reason for removing the role
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
*/ */
removeRole(role) { removeRole(role, reason) {
if (!(role instanceof Role)) role = this.guild.roles.get(role); if (!(role instanceof Role)) role = this.guild.roles.get(role);
if (!role) return Promise.reject(new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake')); if (!role) return Promise.reject(new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake'));
return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id) return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id)
.delete() .delete({ reason })
.then(() => this); .then(() => this);
} }
/** /**
* Removes multiple roles from the member. * Removes multiple roles from the member.
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to remove * @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to remove
* @param {string} [reason] Reason for removing the roles
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
*/ */
removeRoles(roles) { removeRoles(roles, reason) {
const allRoles = this._roles.slice(); const allRoles = this._roles.slice();
if (roles instanceof Collection) { if (roles instanceof Collection) {
for (const role of roles.values()) { for (const role of roles.values()) {
@@ -450,16 +457,17 @@ class GuildMember {
if (index >= 0) allRoles.splice(index, 1); if (index >= 0) allRoles.splice(index, 1);
} }
} }
return this.edit({ roles: allRoles }); return this.edit({ roles: allRoles }, reason);
} }
/** /**
* Set the nickname for the guild member. * Set the nickname for the guild member.
* @param {string} nick The nickname for the guild member * @param {string} nick The nickname for the guild member
* @param {string} [reason] Reason for setting the nickname
* @returns {Promise<GuildMember>} * @returns {Promise<GuildMember>}
*/ */
setNickname(nick) { setNickname(nick, reason) {
return this.edit({ nick }); return this.edit({ nick }, reason);
} }
/** /**