-
Notifications
You must be signed in to change notification settings - Fork 139
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 app command copies #678
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the body is now copied too, does this affect this part of the code for slash commands?
disnake/disnake/ext/commands/slash_core.py
Lines 456 to 460 in 6769f80
if self.description != other.description and "description" not in other.__original_kwargs__: | |
# Allows overriding the default description cog-wide. | |
other.body.description = self.description | |
if self.options != other.options: | |
other.body.options = self.options |
It shouldn't affect it, however, I think I will change |
…isnakeDev/disnake into fix/app-command-copies-in-cogs
c0c1a69
to
5386c20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
This unfortunately doesn't resolve the issue of not being able to overwrite default_member_permissions
with None
, but that's a side effect of how x_attrs
is implemented and can likely only be fixed as part of a general refactor:
class Cog(commands.Cog, slash_command_attrs={"default_member_permissions": 64}):
@commands.slash_command(default_member_permissions=None)
async def cmd(self, _):
...
print(Cog().cmd.default_member_permissions) # -> 64
Regardless, this does fix the core issue, anything beyond that should go in a future PR c:
Is there not a way to unset those default member permissions at all when creating the function? |
Currently not, since it can't differentiate between the parameter default disnake/disnake/ext/commands/base_core.py Lines 147 to 151 in 4c17fdc
This isn't an issue with prefix commands, as their implementation uses **kwargs for literally everything except the name, which in turn results in little to no type-safety.
|
I can do that in a separate PR |
Sounds good. I don't think there are any concrete plans for that yet, but it would be a good idea to take care of #666 first which also refactors parts of the application command system (though mostly related to syncing). |
Summary
This PR fixes app command copies. More specifically, we now ensure that
InvokableApplicationCommand.body
attribute is copied. This fixes the following issue:If you use the
commands.default_member_permissions
decorator after thecommands.slash_command
decorator in a cog, the final command won't have any member permissions set.Steps to reproduce
This code will display permissions of
bugged
asNone
and permissions ofworkaround
as<Permissions ...>
Explanation
Cogs allow to pass "global" kwargs to all cog commands via meta options called
<...>_command_attrs
, see CogMeta.command_attrs. In order to catch those kwargs, disnake rebuilds all commands of a given cog inCog.__new__
. It does so by constructing new command instances, passing original kwargs merged with<...>_command_attrs
. However, some attributes are not being set in<...>Command.__init__
. Instead, they're updated afterwards via decorators and other tools, so we have to copy them separately (this is why all<...>Command
classes have a method called_ensure_assignment_on_copy
). If we applycommands.default_member_permissions
aftercommands.slash_command
, original kwargs won't have the correct default permission value, they'll have it asNone
instead. So we have to copy that value manually, which is what this PR does.Checklist
task lint
task pyright