Add Guild#prune (#723)

* make all changes neat

* run docs build
This commit is contained in:
Gus Caplan
2016-09-21 14:57:14 -05:00
committed by Schuyler Cebulskie
parent 529d7207da
commit 15d7f8e2fe
3 changed files with 31 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -507,6 +507,15 @@ class RESTMethods {
}).catch(reject);
});
}
pruneGuildMembers(guild, days, dry) {
return new Promise((resolve, reject) => {
this.rest.makeRequest(dry ? 'get' : 'post', `${Constants.Endpoints.guildPrune(guild.id)}?days=${days}`, true)
.then(data => {
resolve(data.pruned);
}).catch(reject);
});
}
}
module.exports = RESTMethods;

View File

@@ -504,6 +504,27 @@ class Guild {
return create.then(role => role.edit(data));
}
/**
* 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
* @returns {Promise<number>} The number of members that were/will be kicked
* @example
* // see how many members will be pruned
* guild.prune(12, true)
* .then(pruned => console.log(`This will prune ${pruned} people!`);
* .catch(console.error);
* @example
* // actually prune the members
* guild.prune(12)
* .then(pruned => console.log(`I just pruned ${pruned} people!`);
* .catch(console.error);
*/
prune(days, dry = false) {
if (typeof days !== 'number') throw new TypeError('Days must be a number.');
return this.client.rest.methods.pruneGuildMembers(this, days, dry);
}
/**
* Causes the Client to leave the guild.
* @returns {Promise<Guild>}