Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable logging and built-in validation messages #69

Open
codeblitz97 opened this issue Mar 26, 2024 · 3 comments
Open

Editable logging and built-in validation messages #69

codeblitz97 opened this issue Mar 26, 2024 · 3 comments

Comments

@codeblitz97
Copy link

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

@notunderctrl
Copy link
Member

notunderctrl commented Mar 26, 2024

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:

  1. Stopping the command's run function from being called
  2. Stopping the command from being handled by CommandKit's built-in validations, or
  3. By handling it within the validation function itself.

Important: 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:

  1. Make sure you have a validations directory setup (documentation):

    // src/index.js
    new CommandKit({
      client,
      commandsPath: '...',
      eventsPath: '...',
      validationsPath: '...', // <- REQUIRED
    })
  2. 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.

@codeblitz97
Copy link
Author

Thank you for your clarifications for the validation messages, I'd like to have customized logging message implemented though.

@notunderctrl
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants