mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
Tracking of GUILD_ROLE_CREATE/UPDATE/DELETE events
This commit is contained in:
36
src/client/websocket/packets/handlers/GuildRoleUpdate.js
Normal file
36
src/client/websocket/packets/handlers/GuildRoleUpdate.js
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
const Structure = name => require(`../../../../structures/${name}`);
|
||||
const Constants = require('../../../../util/Constants');
|
||||
const CloneObject = require('../../../../util/CloneObject');
|
||||
|
||||
const Role = Structure('Role');
|
||||
const Guild = Structure('Guild');
|
||||
|
||||
class GuildRoleUpdateHandler extends AbstractHandler {
|
||||
|
||||
constructor(packetManager) {
|
||||
super(packetManager);
|
||||
}
|
||||
|
||||
handle(packet) {
|
||||
let data = packet.d;
|
||||
let client = this.packetManager.client;
|
||||
|
||||
let guild = client.store.get('guilds', data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
let existingRole = guild.store.get('roles', data.role.id);
|
||||
if (existingRole) {
|
||||
let oldRole = CloneObject(existingRole);
|
||||
existingRole.setup(data.role);
|
||||
client.emit(Constants.Events.GUILD_ROLE_UPDATE, guild, oldRole, existingRole);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = GuildRoleUpdateHandler;
|
||||
Reference in New Issue
Block a user