Skip to content

Commit

Permalink
edit example
Browse files Browse the repository at this point in the history
  • Loading branch information
catplvsplus committed May 30, 2024
1 parent 256bc05 commit f12f42e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
40 changes: 40 additions & 0 deletions example/modules/Halts/HandleError.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
6 changes: 3 additions & 3 deletions example/modules/Preconditions/MyPrecondition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
4 changes: 4 additions & 0 deletions example/reciple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -76,6 +77,9 @@ export const config = {
new CommandPermissionsPrecondition(),
MyPrecondition
],
commandHalts: [
HandleError
],
cooldownSweeperOptions: {
timer: 1000 * 60 * 60
},
Expand Down

0 comments on commit f12f42e

Please sign in to comment.