Skip to content

Commit 3a6b259

Browse files
kyranetfavna
authored andcommittedNov 18, 2023
refactor(Command): make type guards check the type
1 parent 04bc519 commit 3a6b259

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎src/lib/structures/Command.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ArgumentStream, Lexer, Parser, type IUnorderedStrategy } from '@sapphire/lexure';
22
import { AliasPiece } from '@sapphire/pieces';
3-
import { isNullish, isObject, type Awaitable } from '@sapphire/utilities';
3+
import { isFunction, isNullish, isObject, type Awaitable } from '@sapphire/utilities';
44
import { ChannelType, ChatInputCommandInteraction, ContextMenuCommandInteraction, type AutocompleteInteraction, type Message } from 'discord.js';
55
import { Args } from '../parsers/Args';
66
import {
@@ -239,28 +239,28 @@ export class Command<PreParseReturn = Args, Options extends Command.Options = Co
239239
* Type-guard that ensures the command supports message commands by checking if the handler for it is present
240240
*/
241241
public supportsMessageCommands(): this is MessageCommand {
242-
return Reflect.has(this, 'messageRun');
242+
return isFunction(Reflect.get(this, 'messageRun'));
243243
}
244244

245245
/**
246246
* Type-guard that ensures the command supports chat input commands by checking if the handler for it is present
247247
*/
248248
public supportsChatInputCommands(): this is ChatInputCommand {
249-
return Reflect.has(this, 'chatInputRun');
249+
return isFunction(Reflect.get(this, 'chatInputRun'));
250250
}
251251

252252
/**
253253
* Type-guard that ensures the command supports context menu commands by checking if the handler for it is present
254254
*/
255255
public supportsContextMenuCommands(): this is ContextMenuCommand {
256-
return Reflect.has(this, 'contextMenuRun');
256+
return isFunction(Reflect.get(this, 'contextMenuRun'));
257257
}
258258

259259
/**
260260
* Type-guard that ensures the command supports handling autocomplete interactions by checking if the handler for it is present
261261
*/
262262
public supportsAutocompleteInteractions(): this is AutocompleteCommand {
263-
return Reflect.has(this, 'autocompleteRun');
263+
return isFunction(Reflect.get(this, 'autocompleteRun'));
264264
}
265265

266266
public override async reload() {

0 commit comments

Comments
 (0)
Please sign in to comment.