disnake icon indicating copy to clipboard operation
disnake copied to clipboard

feat: add `parent` attributes to slash subcommands and groups

Open EQUENOS opened this issue 3 years ago • 2 comments

Summary

This PR implements parent references for slash subcommands.

  • add SubCommandGroup.parent
  • add SubCommand.parent
  • add SubCommand.root_command

Checklist

  • [x] If code changes were made, then they have been tested
    • [x] I have updated the documentation to reflect the changes
    • [x] I have formatted the code properly by running task lint
    • [x] I have type-checked the code by running task pyright
  • [ ] This PR fixes an issue
  • [x] This PR adds something new (e.g. new method or parameters)
  • [ ] (maybe) This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • [ ] This PR is not a code change (e.g. documentation, README, ...)

EQUENOS avatar Sep 21 '22 20:09 EQUENOS

could qualified_name be a property that uses the parent to determine the name?

Yeah but there're no scenarios where subcommands move to another parent. Renames are not supported either so having attributes instead of properties should be fine for now.

EQUENOS avatar Sep 21 '22 20:09 EQUENOS

could qualified_name be a property that uses the parent to determine the name?

Yeah but there're no scenarios where subcommands move to another parent. Renames are not supported either so having attributes instead of properties should be fine for now.

fair

onerandomusername avatar Sep 21 '22 21:09 onerandomusername

Perhaps a parents field

I don't think it's needed because we have root_command. The only use case of parents is to get all parents of a subcommand (with assistance of isinstance), which can be easily done with parent, root_command and isinstance

EQUENOS avatar Sep 23 '22 14:09 EQUENOS

Also another issue with the slash command copy - the parent still points to the old instance

Ah, right, I forgot to test copies... I will fix that.

EQUENOS avatar Sep 23 '22 15:09 EQUENOS

Perhaps a parents field

I don't think it's needed because we have root_command. The only use case of parents is to get all parents of a subcommand (with assistance of isinstance), which can be easily done with parent, root_command and isinstance

We have the same for disnake.ext.commands.Command.

onerandomusername avatar Sep 23 '22 17:09 onerandomusername

InvokableSlashCommand should have a parent attribute too, but this can be None.

onerandomusername avatar Sep 25 '22 01:09 onerandomusername

InvokableSlashCommand should have a parent attribute too, but this can be None.

It's there, I added it after the first review

EQUENOS avatar Sep 25 '22 09:09 EQUENOS