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

Ability to set guild_ids for all commands in a cog #1202

Merged
merged 4 commits into from
Apr 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Apply code suggestions
  • Loading branch information
Middledot committed Mar 27, 2022
commit bd264c93ebd006a97ab5e6679b236c487fa8fe79
6 changes: 4 additions & 2 deletions discord/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ async def bar(self, ctx):
__cog_settings__: Dict[str, Any]
__cog_commands__: List[ApplicationCommand]
__cog_listeners__: List[Tuple[str, str]]
__cog_guild_ids__: List[int]

def __new__(cls: Type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
name, bases, attrs = args
Expand Down Expand Up @@ -220,8 +221,8 @@ def __new__(cls: Type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:

# Update the Command instances dynamically as well
for command in new_cls.__cog_commands__:
if isinstance(command, ApplicationCommand) and command.guild_ids is None and len(new_cls.guild_ids) != 0:
command.guild_ids = new_cls.guild_ids
if isinstance(command, ApplicationCommand) and command.guild_ids is None and len(new_cls.__cog_guild_ids__) != 0:
command.guild_ids = new_cls.__cog_guild_ids__
if not isinstance(command, SlashCommandGroup):
setattr(new_cls, command.callback.__name__, command)
parent = command.parent
Expand Down Expand Up @@ -263,6 +264,7 @@ class Cog(metaclass=CogMeta):
__cog_settings__: ClassVar[Dict[str, Any]]
__cog_commands__: ClassVar[List[ApplicationCommand]]
__cog_listeners__: ClassVar[List[Tuple[str, str]]]
__cog_guild_ids__: ClassVar[List[int]]

def __new__(cls: Type[CogT], *args: Any, **kwargs: Any) -> CogT:
# For issue 426, we need to store a copy of the command objects
Expand Down