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

fix: default subcommand argument behavior #365

Merged
merged 1 commit into from Oct 8, 2022

Conversation

BenSegal855
Copy link
Contributor

This PR fixed the behavior of which default subcommand runs and what arguments get passed to it. With this fix, if a valid group is provided that has a default subcommand, it will always run the default subcommand in that group and will only strip away one argument, the group name. If no valid group or subcommand is given but a top level default subcommand exists, the top level default will run and no arguments will be removed. Below is an example and the code used to generate it.

Example screenshot

image

Test command file used
import { ApplyOptions } from '@sapphire/decorators';
import type { Args } from '@sapphire/framework';
import { Subcommand } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';

@ApplyOptions<Subcommand.Options>({
aliases: ['sg'],
description: 'A message command command with some subcommand groups',
subcommands: [
  {
    type: 'group',
    name: 'config',
    entries: [
      { name: 'edit', messageRun: 'configEdit' },
      { name: 'show', messageRun: 'configShow' }, //, default: true },
      { name: 'remove', messageRun: 'configRemove' },
      { name: 'reset', messageRun: 'configReset' }
    ]
  },
  {
    type: 'method',
    name: 'help',
    messageRun: 'help',
    default: true
  }
]
})
export class UserCommand extends Subcommand {
public async help(message: Message, args: Args) {
  const allArgs = (await args.restResult('string')).unwrapOr('no args received');
  return message.channel.send(`Source: 'help'; Args: \`\`\`${allArgs}\`\`\``);
}

public async configShow(message: Message, args: Args) {
  const allArgs = (await args.restResult('string')).unwrapOr('no args received');
  return message.channel.send(`Source: 'configShow'; Args: \`\`\`${allArgs}\`\`\``);
}

public async configEdit(message: Message, args: Args) {
  const allArgs = (await args.restResult('string')).unwrapOr('no args received');
  return message.channel.send(`Source: 'configEdit'; Args: \`\`\`${allArgs}\`\`\``);
}

public async configRemove(message: Message, args: Args) {
  const allArgs = (await args.restResult('string')).unwrapOr('no args received');
  return message.channel.send(`Source: 'configRemove'; Args: \`\`\`${allArgs}\`\`\``);
}

public async configReset(message: Message, args: Args) {
  const allArgs = (await args.restResult('string')).unwrapOr('no args received');
  return message.channel.send(`Source: 'configReset'; Args: \`\`\`${allArgs}\`\`\``);
}
}

This PR closes #351

@favna favna merged commit 6cef7c6 into sapphiredev:main Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

bug: default message subcommand consuming first argument
2 participants