feat: add support for application command events (#5596)

This commit is contained in:
Jan
2021-05-08 01:25:27 +02:00
committed by GitHub
parent 452ac55a28
commit 9f74f95f69
5 changed files with 90 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
let command;
if (data.guild_id) {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;
command = guild.commands.add(data);
} else {
command = client.application.commands.add(data);
}
/**
* Emitted when an application command is created.
* @event Client#applicationCommandCreate
* @param {ApplicationCommand} command The command which was created
*/
client.emit(Events.APPLICATION_COMMAND_CREATE, command);
};

View File

@@ -0,0 +1,24 @@
'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
let command;
if (data.guild_id) {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;
command = guild.commands.add(data);
guild.commands.cache.delete(data.id);
} else {
command = client.application.commands.add(data);
client.application.commands.cache.delete(data.id);
}
/**
* Emitted when an application command is deleted.
* @event Client#applicationCommandDelete
* @param {ApplicationCommand} command The command which was deleted
*/
client.emit(Events.APPLICATION_COMMAND_DELETE, command);
};

View File

@@ -0,0 +1,26 @@
'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
let oldCommand;
let newCommand;
if (data.guild_id) {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;
oldCommand = guild.commands.cache.get(data.id)?._clone() ?? null;
newCommand = guild.commands.add(data);
} else {
oldCommand = client.application.commands.cache.get(data.id)?._clone() ?? null;
newCommand = client.application.commands.add(data);
}
/**
* Emitted when an application command is updated.
* @event Client#applicationCommandUpdate
* @param {?ApplicationCommand} oldCommand The command before the update
* @param {ApplicationCommand} newCommand The command after the update
*/
client.emit(Events.APPLICATION_COMMAND_UPDATE, oldCommand, newCommand);
};