fix message commands

This commit is contained in:
MARCROCK22 2024-03-18 20:01:50 -04:00
parent 6d47f6ee17
commit add53be029
3 changed files with 21 additions and 13 deletions

View File

@ -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 };

View File

@ -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;

View File

@ -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);
}