From 7c648c1f55198b7b60b7f4f2133f1ebd9060acce Mon Sep 17 00:00:00 2001 From: Yuzu Date: Sun, 23 Apr 2023 13:41:09 +0700 Subject: [PATCH] Added Unload Global --- src/discord/InteractionManager.ts | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/discord/InteractionManager.ts b/src/discord/InteractionManager.ts index c28c87f..44d43e4 100644 --- a/src/discord/InteractionManager.ts +++ b/src/discord/InteractionManager.ts @@ -25,7 +25,7 @@ const EMBEDS = { fields: [ { name: 'Available arguments', - value: '``reloadAll`` ``unloadAll`` ``reloadglobal``' + value: '``reloadAll`` ``unloadAll`` ``reloadGlobal`` ``unloadGlobal``' } ], user: data.getUser() @@ -126,6 +126,36 @@ export default class InteractionManager extends DiscordModule { ); } }, + unloadGlobal: async (data: HybridInteractionMessage) => { + let placeholder: HybridInteractionMessage | undefined; + + let _placeholder = await sendHybridInteractionMessageResponse(data, { + embeds: [EMBEDS.PROCESSING(data)] + }); + if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder); + + try { + await unregisterAllGlobalCommands(); + + if (data && data.isMessage() && placeholder && placeholder.isMessage()) + return placeholder.getMessage().edit({ embeds: [EMBEDS.UNLOADALL_SUCCESS(data)] }); + else if (data.isApplicationCommand()) + return await sendHybridInteractionMessageResponse( + data, + { embeds: [EMBEDS.UNLOADALL_SUCCESS(data)] }, + true + ); + } catch (err) { + if (data && data.isMessage() && placeholder && placeholder.isMessage()) + return placeholder.getMessage().edit({ embeds: [EMBEDS.UNLOADALL_ERROR(data, err)] }); + else if (data.isApplicationCommand()) + return await sendHybridInteractionMessageResponse( + data, + { embeds: [EMBEDS.UNLOADALL_ERROR(data, err)] }, + true + ); + } + }, reloadGlobal: async (data: HybridInteractionMessage) => { let placeholder: HybridInteractionMessage | undefined; @@ -214,6 +244,8 @@ export default class InteractionManager extends DiscordModule { return await funct.reloadGlobal(data); case 'unloadall': return await funct.unloadAll(data); + case 'unloadglobal': + return await funct.unloadGlobal(data); } } }