diff --git a/README.md b/README.md index 4b5d29a..0f0c23a 100644 --- a/README.md +++ b/README.md @@ -298,26 +298,34 @@ There are 4 information messages: - **PERMISSION** - "Insufficient permissions" message (sent when the caller doesn't have enough permissions) - **NOT_FOUND** - "Command not found" message (sent when someone tries to call a command that does not exist) -Each of these messages can be customized with these properties: +Their configuration is stored in _messages.system_ property. -- **enabled** - _boolean_ - enables or disables the message -- **title** - _string_ - title of the message +Each of these messages can be customized with these properties (\* - required): + +- **enabled\*** - _boolean_ - enables or disables the message +- **title\*** - _string_ - title of the message - **bottomText** - _string_ - text below the title (also known as description) - **accentColor** - _ColorResolvable_ - embed color +- **displayDetails** - _boolean_ - whether to display additional informations - **showTimestamp** - _boolean_ - whether to show date and time in the footer - **footer** - _string_ - message footer +- **deleteTimeout** - _number_ - time (ms) after the message gets deleted + +There is also a global _deleteTimeout_ property (_messages.system.deleteTimeout_) ## Help message -You can customize the help message with these properties: +Its configuration is stored in _messages.help_ property. -- **enabled** - _boolean_ - enables or disables the message -- **title** - _string_ - title of the message -- **bottomText** - _string_ - text below the title (also known as description) -- **accentColor** - _ColorResolvable_ - embed color -- **description** - _string_ - description shown in the message itself -- **usage** - _string_ - usage displayed in the message itself -- **visible** - _boolean_ - whether to show the help command in the list +You can customize the help message with these properties (\* - required): + +- **enabled\*** - _boolean_ - enables or disables the message +- **title\*** - _string_ - title of the message +- **bottomText\*** - _string_ - text below the title (also known as description) +- **accentColor\*** - _ColorResolvable_ - embed color +- **description\*** - _string_ - description shown in the message itself +- **usage\*** - _string_ - usage displayed in the message itself +- **visible\*** - _boolean_ - whether to show the help command in the list # Issues diff --git a/src/SystemMessage.ts b/src/SystemMessage.ts index ec2d6de..e15d8ae 100644 --- a/src/SystemMessage.ts +++ b/src/SystemMessage.ts @@ -8,8 +8,10 @@ export interface SystemMessageAppearance { title: string; bottomText?: string; accentColor?: ColorResolvable; + displayDetails?: boolean; showTimestamp?: boolean; footer?: string; + deleteTimeout?: number; } interface SystemMessageData { command?: Command; @@ -31,6 +33,7 @@ export class SystemMessageManager { title: "👮‍♂️ Insufficient permissions", bottomText: "You don't have enough permissions to run this command", accentColor: "#1d1dc4", + displayDetails: true, showTimestamp: true, footer: botName, }; @@ -39,6 +42,7 @@ export class SystemMessageManager { title: "❌ An error occurred", bottomText: "Something went wrong while processing your request.", accentColor: "#ff0000", + displayDetails: true, showTimestamp: true, footer: botName, }; @@ -46,6 +50,7 @@ export class SystemMessageManager { enabled: true, title: "🔍 Command not found", accentColor: "#ff5500", + displayDetails: true, showTimestamp: true, footer: botName, }; @@ -53,8 +58,10 @@ export class SystemMessageManager { enabled: true, title: "✅ Task completed successfully", accentColor: "#00ff00", + displayDetails: true, showTimestamp: true, footer: botName, + deleteTimeout: Infinity, }; this.deleteTimeout = Infinity; } @@ -77,7 +84,7 @@ export class SystemMessageManager { embed.setColor(this[type].accentColor || "#000"); if (this[type].showTimestamp) embed.setTimestamp(); if (this[type].footer) embed.setFooter(this[type].footer || ""); - if (data) { + if (data && this[type].displayDetails) { switch (type) { case "ERROR": if (data.command) { @@ -124,14 +131,29 @@ export class SystemMessageManager { } if (interaction && !(interaction instanceof CommandInteraction)) { const message = await interaction.reply({ embeds: [embed] }); - if (this.deleteTimeout != Infinity && message.deletable) { - setTimeout(async () => { - await message.delete(); - }, this.deleteTimeout || 0); + if (message.deletable) { + if (Number.isFinite(this[type].deleteTimeout)) { + setTimeout(async () => { + await message.delete().catch(); + }, this[type].deleteTimeout); + } else if (this[type].deleteTimeout === undefined && Number.isFinite(this.deleteTimeout)) { + setTimeout(async () => { + await message.delete().catch(); + }, this.deleteTimeout); + } } return message; } else if (interaction && interaction instanceof CommandInteraction) { interaction.replied || interaction.deferred ? await interaction.editReply({ embeds: [embed] }) : await interaction.reply({ embeds: [embed] }); + if (Number.isFinite(this[type].deleteTimeout)) { + setTimeout(async () => { + await interaction.deleteReply().catch(); + }, this[type].deleteTimeout); + } else if (this[type].deleteTimeout === undefined && Number.isFinite(this.deleteTimeout)) { + setTimeout(async () => { + await interaction.deleteReply().catch(); + }, this.deleteTimeout); + } } else { return embed; }