feat: GuildBanManager (#5276)

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com>
Co-authored-by: izexi <43889168+izexi@users.noreply.github.com>
Co-authored-by: Shubham Parihar <shubhamparihar391@gmail.com>
This commit is contained in:
MBR-0001
2021-05-10 12:35:25 +02:00
committed by GitHub
parent 4a06dd1295
commit 6d09160f5b
11 changed files with 320 additions and 88 deletions

View File

@@ -216,29 +216,15 @@ class GuildMemberManager extends BaseManager {
* @returns {Promise<GuildMember|User|Snowflake>} Result object will be resolved as specifically as possible.
* If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot
* be resolved, the user ID will be the result.
* Internally calls the GuildBanManager#create method.
* @example
* // Ban a user by ID (or with a user/guild member object)
* guild.members.ban('84484653687267328')
* .then(user => console.log(`Banned ${user.username || user.id || user} from ${guild.name}`))
* .then(user => console.log(`Banned ${user.username ?? user.id ?? user} from ${guild.name}`))
* .catch(console.error);
*/
ban(user, options = { days: 0 }) {
if (typeof options !== 'object') return Promise.reject(new TypeError('INVALID_TYPE', 'options', 'object', true));
if (options.days) options.delete_message_days = options.days;
const id = this.client.users.resolveID(user);
if (!id) return Promise.reject(new Error('BAN_RESOLVE_ID', true));
return this.client.api
.guilds(this.guild.id)
.bans[id].put({ data: options })
.then(() => {
if (user instanceof GuildMember) return user;
const _user = this.client.users.resolve(id);
if (_user) {
const member = this.resolve(_user);
return member || _user;
}
return id;
});
return this.guild.bans.create(user, options);
}
/**
@@ -246,6 +232,7 @@ class GuildMemberManager extends BaseManager {
* @param {UserResolvable} user The user to unban
* @param {string} [reason] Reason for unbanning user
* @returns {Promise<User>}
* Internally calls the GuildBanManager#remove method.
* @example
* // Unban a user by ID (or with a user/guild member object)
* guild.members.unban('84484653687267328')
@@ -253,12 +240,7 @@ class GuildMemberManager extends BaseManager {
* .catch(console.error);
*/
unban(user, reason) {
const id = this.client.users.resolveID(user);
if (!id) return Promise.reject(new Error('BAN_RESOLVE_ID'));
return this.client.api
.guilds(this.guild.id)
.bans[id].delete({ reason })
.then(() => this.client.users.resolve(user));
return this.guild.bans.remove(user, reason);
}
_fetchSingle({ user, cache, force = false }) {