mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
42 lines
943 B
JavaScript
42 lines
943 B
JavaScript
const Action = require('./Action');
|
|
const Constants = require('../../util/Constants');
|
|
const Util = require('../../util/Util');
|
|
|
|
class GuildRoleUpdateAction extends Action {
|
|
handle(data) {
|
|
const client = this.client;
|
|
const guild = client.guilds.get(data.guild_id);
|
|
|
|
if (guild) {
|
|
const roleData = data.role;
|
|
let oldRole = null;
|
|
|
|
const role = guild.roles.get(roleData.id);
|
|
if (role) {
|
|
oldRole = Util.cloneObject(role);
|
|
role.setup(data.role);
|
|
client.emit(Constants.Events.GUILD_ROLE_UPDATE, oldRole, role);
|
|
}
|
|
|
|
return {
|
|
old: oldRole,
|
|
updated: role,
|
|
};
|
|
}
|
|
|
|
return {
|
|
old: null,
|
|
updated: null,
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Emitted whenever a guild role is updated.
|
|
* @event Client#roleUpdate
|
|
* @param {Role} oldRole The role before the update.
|
|
* @param {Role} newRole The role after the update.
|
|
*/
|
|
|
|
module.exports = GuildRoleUpdateAction;
|