mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
Adding reason parameter to GuildMember's methods (#1710)
* Added reason parameter to GuildMember's methods * Reason parameters are optional
This commit is contained in:
@@ -356,19 +356,21 @@ class GuildMember {
|
||||
/**
|
||||
* Mute/unmute a user.
|
||||
* @param {boolean} mute Whether or not the member should be muted
|
||||
* @param {string} [reason] Reason for muting or unmuting
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
setMute(mute) {
|
||||
return this.edit({ mute });
|
||||
setMute(mute, reason) {
|
||||
return this.edit({ mute }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deafen/undeafen a user.
|
||||
* @param {boolean} deaf Whether or not the member should be deafened
|
||||
* @param {string} [reason] Reason for deafening or undeafening
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
setDeaf(deaf) {
|
||||
return this.edit({ deaf });
|
||||
setDeaf(deaf, reason) {
|
||||
return this.edit({ deaf }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,32 +385,35 @@ class GuildMember {
|
||||
/**
|
||||
* Sets the roles applied to the member.
|
||||
* @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>}
|
||||
*/
|
||||
setRoles(roles) {
|
||||
return this.edit({ roles });
|
||||
setRoles(roles, reason) {
|
||||
return this.edit({ roles }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single role to the member.
|
||||
* @param {Role|Snowflake} role The role or ID of the role to add
|
||||
* @param {string} [reason] Reason for adding the role
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
addRole(role) {
|
||||
addRole(role, reason) {
|
||||
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 (this._roles.includes(role.id)) return Promise.resolve(this);
|
||||
return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id)
|
||||
.put()
|
||||
.put({ reason })
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple roles to the member.
|
||||
* @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>}
|
||||
*/
|
||||
addRoles(roles) {
|
||||
addRoles(roles, reason) {
|
||||
let allRoles;
|
||||
if (roles instanceof Collection) {
|
||||
allRoles = this._roles.slice();
|
||||
@@ -416,28 +421,30 @@ class GuildMember {
|
||||
} else {
|
||||
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.
|
||||
* @param {Role|Snowflake} role The role or ID of the role to remove
|
||||
* @param {string} [reason] Reason for removing the role
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
removeRole(role) {
|
||||
removeRole(role, reason) {
|
||||
if (!(role instanceof Role)) role = this.guild.roles.get(role);
|
||||
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)
|
||||
.delete()
|
||||
.delete({ reason })
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes multiple roles from the member.
|
||||
* @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>}
|
||||
*/
|
||||
removeRoles(roles) {
|
||||
removeRoles(roles, reason) {
|
||||
const allRoles = this._roles.slice();
|
||||
if (roles instanceof Collection) {
|
||||
for (const role of roles.values()) {
|
||||
@@ -450,16 +457,17 @@ class GuildMember {
|
||||
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.
|
||||
* @param {string} nick The nickname for the guild member
|
||||
* @param {string} [reason] Reason for setting the nickname
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
setNickname(nick) {
|
||||
return this.edit({ nick });
|
||||
setNickname(nick, reason) {
|
||||
return this.edit({ nick }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user