mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
feat: add support for application command events (#5596)
This commit is contained in:
22
src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js
Normal file
22
src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js
Normal 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);
|
||||
};
|
||||
24
src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js
Normal file
24
src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js
Normal 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);
|
||||
};
|
||||
26
src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js
Normal file
26
src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js
Normal 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);
|
||||
};
|
||||
Reference in New Issue
Block a user