underctrl-io / commandkit

Only focus on what matters - Let CommandKit handle your commands and events in your Discord.js projects!
https://commandkit.js.org
MIT License
82 stars 9 forks source link

`ValidationProps` interaction does not have the `.reply()` method #46

Closed lassejlv closed 6 months ago

lassejlv commented 7 months ago

https://commandkit.js.org/guide/validation-file-setup then using the ValidationProps. Then if you use interaction.reply(...) it will throw an error. Version: 0.1.10

notunderctrl commented 7 months ago

Hi. Can you please share the exact error you're facing. Thanks

lassejlv commented 7 months ago

When using ValidationProps type, and using .reply you are getting an type error.

notunderctrl commented 7 months ago

I was able to reproduce the issue:

import type { ValidationProps } from 'commandkit';

export default function ({ interaction, commandObj, handler }: ValidationProps) {    
    interaction.reply('This does not work.'); // Property 'reply' does not exist on type 'ChatInputCommandInteraction<CacheType> | ContextMenuCommandInteraction<CacheType> | AutocompleteInteraction<...>'.
}

Reason

With version 1.10, validations also support autocomplete. This is a new feature in command files.

With this new update, the interaction object can now also be of type AutocompleteInteraction alongside the previous ChatInputCommandInteraction and ContextMenuCommandInteraction.

Fix

Since you can't "reply" to the AutocompleteInteraction type (you can only "respond" with autocomplete), you need to add a check in your validation to ensure that the interaction type you're handling is of either ChatInputCommandInteraction, or ContextMenuCommandInteraction.

import type { ValidationProps } from 'commandkit';

export default function ({ interaction, commandObj, handler }: ValidationProps) {
    if (interaction.isAutocomplete()) return;

    interaction.reply('This now works!');
}
notunderctrl commented 7 months ago

Gonna leave this open for now for feedback

lassejlv commented 7 months ago

Arr alright thanks for the help :) keep up the good work!