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

Support modularizing the registration of a slash command. #236

Open
expeehaa opened this issue Sep 13, 2023 · 0 comments
Open

Support modularizing the registration of a slash command. #236

expeehaa opened this issue Sep 13, 2023 · 0 comments

Comments

@expeehaa
Copy link

The traditional commands can be easily modularized by extending a module with Discordrb::Commands::CommandContainer. With slash commands however, there is a second method to register the command on Discord. As far as I can tell, currently, only the application_command method can be factored out into separate modules in the same way as traditional commands by extending with Discordrb::EventContainer. The method register_application_command is defined as an instance method of Discordrb::Bot, which therefore is unavailable in those separate modules.
It would be nice if discordrb allowed developers to extract the application commands together with the registration to separate modules.

I’m not sure how a good implementation should look like. The method #register_application_command obviously does not belong in Discordrb::EventContainer. Also, it works differently from #application_command since it does not store anything but directly talks to the Discord API.
Maybe both could be combined in a single new module anyway, roughly like this:

  1. Create a new module, e.g. Discordrb::ApplicationCommandContainer.
  2. Move everything about application commands from Discordrb::EventContainer into the new module.
  3. Define a method Discordrb::ApplicationCommandContainer#register_application_command whose usage is exactly like Discordrb::Bot#register_application_command, but instead of immediately talking to the Discord API, it yields to the block and stores the parameters and builders in a variable.
  4. Include the new module in Discordrb::Bot. The existing Discordrb::Bot#register_application_command would then shadow the one from the new module (this could be a bad practice, not sure), which allows to still register application commands whenever one pleases.
  5. When the bot is actually started, send the stored command registrations to the Discord API.

I think I prefer the above approach, but for backwards compatibility step 2 could be removed or postponed until 4.0 or so.

I’ld be happy to create a PR if accepted.

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

No branches or pull requests

1 participant