From f12f42e0f6755032431c018f485da34b5c6cee7d Mon Sep 17 00:00:00 2001 From: Cat++ <69035887+NotGhex@users.noreply.github.com> Date: Thu, 30 May 2024 16:51:47 +0800 Subject: [PATCH] edit example --- example/modules/Halts/HandleError.js | 40 +++++++++++++++++++ .../modules/Preconditions/MyPrecondition.js | 6 +-- example/reciple.mjs | 4 ++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 example/modules/Halts/HandleError.js diff --git a/example/modules/Halts/HandleError.js b/example/modules/Halts/HandleError.js new file mode 100644 index 00000000..28a2e346 --- /dev/null +++ b/example/modules/Halts/HandleError.js @@ -0,0 +1,40 @@ +// @ts-check +import { CommandHaltReason, CommandType } from 'reciple'; + +/** + * @type {import('reciple').CommandHaltData} + */ +export default { + id: 'org.reciple.js.handleerror', + commandTypes: [CommandType.ContextMenuCommand, CommandType.MessageCommand, CommandType.SlashCommand], + /** + * + * @param {import('reciple').AnyCommandHaltTriggerData} data + * @returns + */ + async halt(data) { + if (data.reason !== CommandHaltReason.Error) return; + + const content = `An error occured while executing this command`; + + switch (data.commandType) { + case CommandType.ContextMenuCommand: + case CommandType.SlashCommand: + const interaction = data.executeData.interaction; + + if (interaction.replied || interaction.deferred) { + await interaction.editReply(content); + } else { + await interaction.reply(content); + } + break; + case CommandType.MessageCommand: + await data.executeData.message.reply(content); + break; + } + + console.log(data.error); + + return true; + } +}; diff --git a/example/modules/Preconditions/MyPrecondition.js b/example/modules/Preconditions/MyPrecondition.js index ac6e5251..fb704b9b 100644 --- a/example/modules/Preconditions/MyPrecondition.js +++ b/example/modules/Preconditions/MyPrecondition.js @@ -7,12 +7,12 @@ export default { id: 'command.precondition.lol', disabled: false, contextMenuCommandExecute: execute => { - return false; + return true; }, messageCommandExecute: excute => { - return false; + return true; }, slashCommandExecute: execute => { - return false; + return true; } }; diff --git a/example/reciple.mjs b/example/reciple.mjs index 61977bd6..4aa86d62 100644 --- a/example/reciple.mjs +++ b/example/reciple.mjs @@ -2,6 +2,7 @@ import { CooldownPrecondition, CommandPermissionsPrecondition } from 'reciple'; import { IntentsBitField } from 'discord.js'; import MyPrecondition from './modules/Preconditions/MyPrecondition.js'; +import HandleError from './modules/Halts/HandleError.js'; /** * @type {import('reciple').RecipleConfig} @@ -76,6 +77,9 @@ export const config = { new CommandPermissionsPrecondition(), MyPrecondition ], + commandHalts: [ + HandleError + ], cooldownSweeperOptions: { timer: 1000 * 60 * 60 },