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 - Allow mixing groups and subcommands #244

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

itsthedevman
Copy link

Summary

What is the problem I'm trying to solve?

I want to register the following commands:

/documents archive
/documents set password
/documents set owner
/documents show

What is happening that is unexpected?

Once the code gets to /documents show, it raises because /documents set (owner,password) has already been registered as a group. This structure is valid as described in Discord's API documentation.

Code example

bot = Discordrb::Bot.new(...)

bot.register_application_command(:documents, "", server_id: "") do |command|
  command.subcommand(:archive)

  command.subcommand_group(:set, "") do |group|
    group.subcommand(:password)
    group.subcommand(:owner)
  end

  command.subcommand(:show)
end

bot.application_command(:documents).subcommand(:archive) { |e| ... }

bot.application_command(:documents).group(:set) do |group|
  group.subcommand(:password) { |e| ... }
  group.subcommand(:owner) { |e| ... }
end

bot.application_command(:documents).subcommand(:show) { |e| ... }

Once the fix is in place, we can see the structure of the @subcommands hash is valid even with the mixture of groups and subcommands:

{:archive=>#<Proc:0x00001 (lambda)>,
 :show=>#<Proc:0x00004 (lambda)>,
 :set=>{:password=>#<Proc:0x00002 (lambda)>, :owner=>#<Proc:0x00003 (lambda)>}}

Fixed

  • Added a name check during sub-command validation to allow mixing subcommands and groups so long as they don't share the same name.

Copy link
Contributor

@Droid00000 Droid00000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this out. Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants