mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
Added guild.unban
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -14,6 +14,7 @@ class ActionsManager {
|
||||
this.register('GuildDelete');
|
||||
this.register('GuildUpdate');
|
||||
this.register('GuildMemberRemove');
|
||||
this.register('GuildBanRemove');
|
||||
this.register('GuildRoleCreate');
|
||||
this.register('GuildRoleDelete');
|
||||
this.register('GuildRoleUpdate');
|
||||
|
||||
18
src/client/actions/GuildBanRemove.js
Normal file
18
src/client/actions/GuildBanRemove.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
|
||||
class GuildBanRemove extends Action {
|
||||
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
const user = client.dataManager.newUser(data.user);
|
||||
|
||||
if (guild && user) {
|
||||
client.emit(Constants.Events.GUILD_BAN_REMOVE, guild, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildBanRemove;
|
||||
@@ -354,7 +354,7 @@ class RESTMethods {
|
||||
updateGuildMember(member, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (data.channel) {
|
||||
data.channel_id = this.client.resolver.resolveChannel(data.channel).id;
|
||||
data.channel_id = this.rest.client.resolver.resolveChannel(data.channel).id;
|
||||
}
|
||||
if (data.roles) {
|
||||
if (data.roles instanceof Map) {
|
||||
@@ -395,6 +395,25 @@ class RESTMethods {
|
||||
});
|
||||
}
|
||||
|
||||
unbanGuildMember(guild, member) {
|
||||
return new Promise((resolve, reject) => {
|
||||
member = this.rest.client.resolver.resolveUser(member);
|
||||
if (!member) {
|
||||
throw new Error('cannot unban a user that is not a user resolvable');
|
||||
}
|
||||
const listener = (eGuild, eUser) => {
|
||||
if (guild.id === guild.id && member.id === eUser.id) {
|
||||
this.rest.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener);
|
||||
resolve(eUser);
|
||||
}
|
||||
};
|
||||
this.rest.client.on(Constants.Events.GUILD_BAN_REMOVE, listener);
|
||||
this.rest.makeRequest('del', `${Constants.Endpoints.guildBans(guild.id)}/${member.id}`, true)
|
||||
.then(() => {})
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
updateGuildRole(role, _data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
/*
|
||||
|
||||
@@ -2,20 +2,13 @@
|
||||
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
|
||||
const Constants = require('../../../../util/Constants');
|
||||
|
||||
class GuildBanRemoveHandler extends AbstractHandler {
|
||||
|
||||
handle(packet) {
|
||||
const data = packet.d;
|
||||
const client = this.packetManager.client;
|
||||
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
const user = client.users.get(data.user.id);
|
||||
|
||||
if (guild && user) {
|
||||
client.emit(Constants.Events.GUILD_BAN_REMOVE, guild, user);
|
||||
}
|
||||
client.actions.GuildBanRemove.handle(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -538,6 +538,20 @@ class Guild {
|
||||
return this.edit({ splash });
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbans a member from the Guild
|
||||
* @param {UserResolvable} member the member to unban
|
||||
* @returns {Promise<User, Error>}
|
||||
* @example
|
||||
* // unban a member
|
||||
* guild.unban('123123123123')
|
||||
* .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
|
||||
* .catch(reject);
|
||||
*/
|
||||
unban(member) {
|
||||
return this.client.rest.methods.unbanGuildMember(this, member);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL to this guild's icon (if it has one, otherwise it returns null)
|
||||
* @type {?String}
|
||||
|
||||
Reference in New Issue
Block a user