mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
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:
@@ -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 }) {
|
||||
|
||||
Reference in New Issue
Block a user