Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for application command events (#5596)
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 24 additions & 0 deletions
24
src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 26 additions & 0 deletions
26
src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters