Open codeblitz97 opened 3 months ago
The default interaction replies such as ❌ Not enough permissions
and ❌ Only developers can use this command
can be customized using your own validation functions (more on that below).
Customization for logs shown in the console however (✅ Loaded 1 global commands.
) is currently not available.
If you'd like to use custom messages for the default interaction replies mentioned above, you can create your own custom validation function(s).
For context: Validations are functions that are called before a command is handled by CommandKit. Validation functions can control the lifecycle of a command by either:
run
function from being calledImportant: Validation functions are called before CommandKit's built-in validations so you have more control over the lifecycle of commands handled.
To setup your own custom validation function that overrides the default interaction replies, you can do the following:
Make sure you have a validations directory setup (documentation):
// src/index.js
new CommandKit({
client,
commandsPath: '...',
eventsPath: '...',
validationsPath: '...', // <- REQUIRED
})
Create a new validation function inside your validations directory to handle your specific use case (documentation):
// src/validations/dev-only-commands.js
module.exports = ({ interaction, commandObj, handler }) => {
if (
commandObj.options?.devOnly &&
!handler.devUserIds.includes(interaction.user.id)
) {
interaction.reply(
"This is a custom validation message. Only developers can run this command."
);
return true; // Stop the command and other validations from being executed
}
};
The above example shows how you can reply with a custom message by checking for the devOnly
property inside the options
object. If you'd like to do the same with other messages such as "Not enough permissions", you can do that with a validation function as well. You can see how CommandKit's built-in validation functions work to get a better understanding (or to replicate in your own validation function):
In each of the above built-in CommandKit validations, assume targetCommand
to be the commandObj
property from your validation function.
Thank you for your clarifications for the validation messages, I'd like to have customized logging message implemented though.
Thank you for the suggestion. We'll try to find a way to add customized logging which doesn't result to a messy codebase because that's currently the biggest concern with this feature.
Currently, we cannot edit the logging and built-in validation messages.
✅ Loaded 1 global commands.
❌ Only developers can use this command
Make it so we can customize it with our desire