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

[SFW-80] bug: provided a subcommand group is configured with a default match and the command is ran with only the name of the subcommand the default match doesn't get executed. #464

Open
1 task done
favna opened this issue Aug 12, 2023 · 0 comments

Comments

@favna
Copy link
Member

favna commented Aug 12, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

Provided the following subcommand array:

subcommands: [
  {
    type: 'group',
    name: 'config',
    entries: [
      { name: 'edit', messageRun: 'configEdit' },
      { name: 'show', messageRun: 'configShow', default: true },
      { name: 'remove', messageRun: 'configRemove' },
      { name: 'reset', messageRun: 'configReset' }
    ]
  }
]

The expected behaviour is that running !command config would execute show as that is the configured default.

Currently however an error is thrown due to subcommandName.isSome() returning false here:

if (mapping.type === 'group' && subcommandOrGroup.isSome() && subcommandName.isSome()) {

Steps To Reproduce

  1. Copy the following subcommand code as a new command:
import { Subcommand } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';

export class UserCommand extends Subcommand {
  public constructor(context: Subcommand.Context) {
    super(context, {
      aliases: ['sg'],
      description: 'A message 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' }
          ]
        }
      ]
    });
  }
  public async configShow(message: Message) {
    return message.channel.send('Showing!');
  }

  public async configEdit(message: Message) {
    return message.channel.send('Editing!');
  }

  public async configRemove(message: Message) {
    return message.channel.send('Removing!');
  }

  public async configReset(message: Message) {
    return message.channel.send('Resetting!');
  }
}
  1. Run !sg config
  2. Observe that show subcommand does not get executed and instead a messageSubcommandNoMatch error is thrown.

Expected behavior

The default subcommand within the subcommand group executes as described

Screenshots

No response

Additional context

No response

SFW-80

@favna favna changed the title bug: provided a subcommand group is configured with a default match and the command is ran with only the name of the subcommand the default match doesn't get executed. [SFW-80] bug: provided a subcommand group is configured with a default match and the command is ran with only the name of the subcommand the default match doesn't get executed. Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant