diff --git a/src/client/onmessagecreate.ts b/src/client/onmessagecreate.ts index 3a2f85a..f4b9451 100644 --- a/src/client/onmessagecreate.ts +++ b/src/client/onmessagecreate.ts @@ -44,15 +44,15 @@ function getCommandFromContent( const command = groupName || subcommandName ? (parent.options?.find(opt => { - if (opt instanceof SubCommand) { - if (groupName) { - if (opt.group !== groupName) return false; + if (opt instanceof SubCommand) { + if (groupName) { + if (opt.group !== groupName) return false; + } + if (opt.group && !groupName) return false; + return subcommandName === opt.name; } - if (opt.group && !groupName) return false; - return subcommandName === opt.name; - } - return false; - }) as SubCommand) + return false; + }) as SubCommand) : parent; return { @@ -95,6 +95,7 @@ export async function onMessageCreate( }; const args = (self.options?.commands?.argsParser ?? defaultArgsParser)(content, command); const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved); + console.log({ options, errors }); const optionsResolver = new OptionResolver(self, options, parent as Command, message.guildId, resolved); const context = new CommandContext(self, message, optionsResolver, shardId, command); const extendContext = self.options?.context?.(message) ?? {}; @@ -364,6 +365,11 @@ async function parseOptions( value, } as APIApplicationCommandInteractionDataOption); } + if (i.required && value === undefined) + errors.push({ + error: 'Option is required but returned undefined', + name: i.name, + }); } return { errors, options }; diff --git a/src/commands/applications/chat.ts b/src/commands/applications/chat.ts index 9fa003e..58ec7e8 100644 --- a/src/commands/applications/chat.ts +++ b/src/commands/applications/chat.ts @@ -130,15 +130,14 @@ class BaseCommand { ctx: CommandContext<{}, never>, resolver: OptionResolver, ): Promise<[boolean, OnOptionsReturnObject]> { - const command = resolver.getCommand(); - if (!command?.options?.length) { + if (!this?.options?.length) { return [false, {}]; } const data: OnOptionsReturnObject = {}; let errored = false; - for (const i of command.options ?? []) { + for (const i of this.options ?? []) { try { - const option = command.options!.find(x => x.name === i.name) as __CommandOption; + const option = this.options!.find(x => x.name === i.name) as __CommandOption; const value = resolver.getHoisted(i.name)?.value !== undefined ? await new Promise( @@ -147,7 +146,6 @@ class BaseCommand { res(resolver.getValue(i.name)), ) : undefined; - if (value === undefined) { if (option.required) { errored = true; diff --git a/src/structures/Message.ts b/src/structures/Message.ts index dcea30e..3510c37 100644 --- a/src/structures/Message.ts +++ b/src/structures/Message.ts @@ -46,6 +46,10 @@ export class BaseMessage extends DiscordBase { this.patch(data); } + get user() { + return this.author; + } + createComponentCollector(options?: ListenerOptions) { return this.client.components.createComponentCollector(this.id, options); }