mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
Backporting audit log reasons and createRole with position for 11.2 (#1810)
* Backporting audit log reasons and createRole with position for 11.2 * Sending kick reason via header rather than via query
This commit is contained in:
@@ -535,6 +535,7 @@ class Guild {
|
||||
/**
|
||||
* Updates the guild with new information - e.g. a new name.
|
||||
* @param {GuildEditData} data The data to update the guild with
|
||||
* @param {string} [reason] Reason for editing this guild
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Set the guild name and region
|
||||
@@ -545,7 +546,7 @@ class Guild {
|
||||
* .then(updated => console.log(`New guild name ${updated.name} in region ${updated.region}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(data) {
|
||||
edit(data, reason) {
|
||||
const _data = {};
|
||||
if (data.name) _data.name = data.name;
|
||||
if (data.region) _data.region = data.region;
|
||||
@@ -559,21 +560,23 @@ class Guild {
|
||||
if (typeof data.explicitContentFilter !== 'undefined') {
|
||||
_data.explicit_content_filter = Number(data.explicitContentFilter);
|
||||
}
|
||||
return this.client.rest.methods.updateGuild(this, _data);
|
||||
return this.client.rest.methods.updateGuild(this, _data, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the level of the explicit content filter.
|
||||
* @param {number} explicitContentFilter The new level of the explicit content filter
|
||||
* @param {string} [reason] Reason for changing the level of the guild's explicit content filter
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setExplicitContentFilter(explicitContentFilter) {
|
||||
return this.edit({ explicitContentFilter });
|
||||
setExplicitContentFilter(explicitContentFilter, reason) {
|
||||
return this.edit({ explicitContentFilter }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the name of the guild.
|
||||
* @param {string} name The new name of the guild
|
||||
* @param {string} [reason] Reason for changing the guild's name
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild name
|
||||
@@ -581,13 +584,14 @@ class Guild {
|
||||
* .then(updated => console.log(`Updated guild name to ${guild.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setName(name) {
|
||||
return this.edit({ name });
|
||||
setName(name, reason) {
|
||||
return this.edit({ name }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the region of the guild.
|
||||
* @param {string} region The new region of the guild
|
||||
* @param {string} [reason] Reason for changing the guild's region
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild region
|
||||
@@ -595,13 +599,14 @@ class Guild {
|
||||
* .then(updated => console.log(`Updated guild region to ${guild.region}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setRegion(region) {
|
||||
return this.edit({ region });
|
||||
setRegion(region, reason) {
|
||||
return this.edit({ region }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the verification level of the guild.
|
||||
* @param {number} verificationLevel The new verification level of the guild
|
||||
* @param {string} [reason] Reason for changing the guild's verification level
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild verification level
|
||||
@@ -609,13 +614,14 @@ class Guild {
|
||||
* .then(updated => console.log(`Updated guild verification level to ${guild.verificationLevel}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setVerificationLevel(verificationLevel) {
|
||||
return this.edit({ verificationLevel });
|
||||
setVerificationLevel(verificationLevel, reason) {
|
||||
return this.edit({ verificationLevel }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the AFK channel of the guild.
|
||||
* @param {ChannelResolvable} afkChannel The new AFK channel
|
||||
* @param {string} [reason] Reason for changing the guild's AFK channel
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild AFK channel
|
||||
@@ -623,22 +629,24 @@ class Guild {
|
||||
* .then(updated => console.log(`Updated guild AFK channel to ${guild.afkChannel}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setAFKChannel(afkChannel) {
|
||||
return this.edit({ afkChannel });
|
||||
setAFKChannel(afkChannel, reason) {
|
||||
return this.edit({ afkChannel }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the system channel of the guild.
|
||||
* @param {ChannelResolvable} systemChannel The new system channel
|
||||
* @param {string} [reason] Reason for changing the guild's system channel
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setSystemChannel(systemChannel) {
|
||||
return this.edit({ systemChannel });
|
||||
setSystemChannel(systemChannel, reason) {
|
||||
return this.edit({ systemChannel }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the AFK timeout of the guild.
|
||||
* @param {number} afkTimeout The time in seconds that a user must be idle to be considered AFK
|
||||
* @param {string} [reason] Reason for changing the guild's AFK timeout
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild AFK channel
|
||||
@@ -646,13 +654,14 @@ class Guild {
|
||||
* .then(updated => console.log(`Updated guild AFK timeout to ${guild.afkTimeout}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setAFKTimeout(afkTimeout) {
|
||||
return this.edit({ afkTimeout });
|
||||
setAFKTimeout(afkTimeout, reason) {
|
||||
return this.edit({ afkTimeout }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new guild icon.
|
||||
* @param {Base64Resolvable} icon The new icon of the guild
|
||||
* @param {string} [reason] Reason for changing the guild's icon
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild icon
|
||||
@@ -660,13 +669,14 @@ class Guild {
|
||||
* .then(updated => console.log('Updated the guild icon'))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setIcon(icon) {
|
||||
return this.edit({ icon });
|
||||
setIcon(icon, reason) {
|
||||
return this.edit({ icon }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new owner of the guild.
|
||||
* @param {GuildMemberResolvable} owner The new owner of the guild
|
||||
* @param {string} [reason] Reason for setting the new owner
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild owner
|
||||
@@ -674,13 +684,14 @@ class Guild {
|
||||
* .then(updated => console.log(`Updated the guild owner to ${updated.owner.username}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setOwner(owner) {
|
||||
return this.edit({ owner });
|
||||
setOwner(owner, reason) {
|
||||
return this.edit({ owner }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new guild splash screen.
|
||||
* @param {Base64Resolvable} splash The new splash screen of the guild
|
||||
* @param {string} [reason] Reason for changing the guild's splash screen
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild splash
|
||||
@@ -688,8 +699,8 @@ class Guild {
|
||||
* .then(updated => console.log('Updated the guild splash'))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setSplash(splash) {
|
||||
return this.edit({ splash });
|
||||
setSplash(splash, reason) {
|
||||
return this.edit({ splash }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -755,6 +766,7 @@ class Guild {
|
||||
/**
|
||||
* Unbans a user from the guild.
|
||||
* @param {UserResolvable} user The user to unban
|
||||
* @param {string} [reason] Reason for unbanning the user
|
||||
* @returns {Promise<User>}
|
||||
* @example
|
||||
* // Unban a user by ID (or with a user/guild member object)
|
||||
@@ -762,14 +774,15 @@ class Guild {
|
||||
* .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
unban(user) {
|
||||
return this.client.rest.methods.unbanGuildMember(this, user);
|
||||
unban(user, reason) {
|
||||
return this.client.rest.methods.unbanGuildMember(this, user, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prunes members from the guild based on how long they have been inactive.
|
||||
* @param {number} days Number of days of inactivity required to kick
|
||||
* @param {boolean} [dry=false] If true, will return number of users that will be kicked, without actually doing it
|
||||
* @param {string} [reason] Reason for this prune
|
||||
* @returns {Promise<number>} The number of members that were/will be kicked
|
||||
* @example
|
||||
* // See how many members will be pruned
|
||||
@@ -782,9 +795,9 @@ class Guild {
|
||||
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
pruneMembers(days, dry = false) {
|
||||
pruneMembers(days, dry = false, reason) {
|
||||
if (typeof days !== 'number') throw new TypeError('Days must be a number.');
|
||||
return this.client.rest.methods.pruneGuildMembers(this, days, dry);
|
||||
return this.client.rest.methods.pruneGuildMembers(this, days, dry, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -799,7 +812,8 @@ class Guild {
|
||||
* Creates a new channel in the guild.
|
||||
* @param {string} name The name of the new channel
|
||||
* @param {string} type The type of the new channel, either `text` or `voice`
|
||||
* @param {Array<PermissionOverwrites|Object>} overwrites Permission overwrites to apply to the new channel
|
||||
* @param {Array<PermissionOverwrites|Object>} [overwrites] Permission overwrites to apply to the new channel
|
||||
* @param {string} [reason] Reason for creating this channel
|
||||
* @returns {Promise<TextChannel|VoiceChannel>}
|
||||
* @example
|
||||
* // Create a new text channel
|
||||
@@ -807,8 +821,8 @@ class Guild {
|
||||
* .then(channel => console.log(`Created new channel ${channel}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
createChannel(name, type, overwrites) {
|
||||
return this.client.rest.methods.createChannel(this, name, type, overwrites);
|
||||
createChannel(name, type, overwrites, reason) {
|
||||
return this.client.rest.methods.createChannel(this, name, type, overwrites, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -834,6 +848,7 @@ class Guild {
|
||||
/**
|
||||
* Creates a new role in the guild with given information
|
||||
* @param {RoleData} [data] The data to update the role with
|
||||
* @param {string} [reason] Reason for creating this role
|
||||
* @returns {Promise<Role>}
|
||||
* @example
|
||||
* // Create a new role
|
||||
@@ -849,8 +864,8 @@ class Guild {
|
||||
* .then(role => console.log(`Created role ${role}`))
|
||||
* .catch(console.error)
|
||||
*/
|
||||
createRole(data = {}) {
|
||||
return this.client.rest.methods.createGuildRole(this, data);
|
||||
createRole(data = {}, reason) {
|
||||
return this.client.rest.methods.createGuildRole(this, data, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -858,6 +873,7 @@ class Guild {
|
||||
* @param {BufferResolvable|Base64Resolvable} attachment The image for the emoji
|
||||
* @param {string} name The name for the emoji
|
||||
* @param {Collection<Snowflake, Role>|Role[]} [roles] Roles to limit the emoji to
|
||||
* @param {string} [reason] Reason for creating the emoji
|
||||
* @returns {Promise<Emoji>} The created emoji
|
||||
* @example
|
||||
* // Create a new emoji from a url
|
||||
@@ -870,14 +886,14 @@ class Guild {
|
||||
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
createEmoji(attachment, name, roles) {
|
||||
createEmoji(attachment, name, roles, reason) {
|
||||
return new Promise(resolve => {
|
||||
if (typeof attachment === 'string' && attachment.startsWith('data:')) {
|
||||
resolve(this.client.rest.methods.createEmoji(this, attachment, name, roles));
|
||||
resolve(this.client.rest.methods.createEmoji(this, attachment, name, roles, reason));
|
||||
} else {
|
||||
this.client.resolver.resolveBuffer(attachment).then(data => {
|
||||
const dataURI = this.client.resolver.resolveBase64(data);
|
||||
resolve(this.client.rest.methods.createEmoji(this, dataURI, name, roles));
|
||||
resolve(this.client.rest.methods.createEmoji(this, dataURI, name, roles, reason));
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -886,11 +902,12 @@ class Guild {
|
||||
/**
|
||||
* Delete an emoji.
|
||||
* @param {Emoji|string} emoji The emoji to delete
|
||||
* @param {string} [reason] Reason for deleting the emoji
|
||||
* @returns {Promise}
|
||||
*/
|
||||
deleteEmoji(emoji) {
|
||||
deleteEmoji(emoji, reason) {
|
||||
if (!(emoji instanceof Emoji)) emoji = this.emojis.get(emoji);
|
||||
return this.client.rest.methods.deleteEmoji(emoji);
|
||||
return this.client.rest.methods.deleteEmoji(emoji, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user