refactor(Interaction): See description

- Change the data returned when interacting, from `nonce: Snowflake` to `data: InteractionResponseBody` (use try catch to detect command errors)
- Full support for Autocomplete (Automatically selects the first option)
This commit is contained in:
March 7th
2022-07-12 19:30:18 +07:00
parent ec809a0f95
commit 1a6b3addfe
14 changed files with 198 additions and 37 deletions

View File

@@ -19,5 +19,5 @@ module.exports = (client, { d: data }) => {
* @param {AutocompleteResponse} data Data
* @deprecated Test only
*/
client.emit(Events.DEBUG, data);
client.emit(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, data);
};

View File

@@ -8,6 +8,9 @@ const { Events } = require('../../../util/Constants');
*/
module.exports = (client, packet) => {
if (client.user.bot) client.actions.InteractionCreate.handle(packet.d);
else client.emit(Events.INTERACTION_CREATE, packet.d);
if (client.user.bot) {
client.actions.InteractionCreate.handle(packet.d);
} else {
client.emit(Events.INTERACTION_CREATE, packet.d);
}
};

View File

@@ -8,4 +8,8 @@ module.exports = (client, { d: data }) => {
* @param {InteractionResponseBody} data data
*/
client.emit(Events.INTERACTION_FAILURE, data);
client.emit('interactionResponse', {
status: false,
metadata: data,
});
};

View File

@@ -8,4 +8,8 @@ module.exports = (client, { d: data }) => {
* @param {InteractionResponseBody} data data
*/
client.emit(Events.INTERACTION_SUCCESS, data);
client.emit('interactionResponse', {
status: true,
metadata: data,
});
};

View File

@@ -5,6 +5,7 @@ const handlers = Object.fromEntries([
['RESUMED', require('./RESUMED')],
['RELATIONSHIP_ADD', require('./RELATIONSHIP_ADD')],
['RELATIONSHIP_REMOVE', require('./RELATIONSHIP_REMOVE')],
['APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE', require('./APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE')],
['APPLICATION_COMMAND_CREATE', require('./APPLICATION_COMMAND_CREATE')],
['APPLICATION_COMMAND_DELETE', require('./APPLICATION_COMMAND_DELETE')],
['APPLICATION_COMMAND_UPDATE', require('./APPLICATION_COMMAND_UPDATE')],