diff --git a/README.md b/README.md index 73a0cf552..972abb999 100644 --- a/README.md +++ b/README.md @@ -83,4 +83,5 @@ def setup(bot): - [dispike](https://github.com/ms7m/dispike) - [discord-interactions-python](https://github.com/discord/discord-interactions-python) - Or for other languages: - - [discord-api-docs Community Resources: Interactions](https://discord.com/developers/docs/topics/community-resources#interactions) \ No newline at end of file + - [discord-api-docs Community Resources: Interactions](https://discord.com/developers/docs/topics/community-resources#interactions) + diff --git a/discord_slash/client.py b/discord_slash/client.py index 840565647..6493c6b28 100644 --- a/discord_slash/client.py +++ b/discord_slash/client.py @@ -69,6 +69,7 @@ def __init__( self.logger.warning( "Detected discord.Client! It is highly recommended to use `commands.Bot`. Do not add any `on_socket_response` event." ) + self._discord.on_socket_response = self.on_socket_response self.has_listener = False else: @@ -502,6 +503,10 @@ def add_slash_command( name = name or cmd.__name__ name = name.lower() guild_ids = guild_ids if guild_ids else [] + if not all(isinstance(item, int) for item in guild_ids) and guild_ids is not []: + raise error.IncorrectGuildIDType( + f"The snowflake IDs {guild_ids} given are not a list of integers. Because of discord.py convention, please use integer IDs instead. Furthermore, the command '{name}' will be deactivated and broken until fixed." + ) if name in self.commands: tgt = self.commands[name] if not tgt.has_subcommands: @@ -580,6 +585,10 @@ def add_subcommand( name = name.lower() description = description or getdoc(cmd) guild_ids = guild_ids if guild_ids else [] + if not all(isinstance(item, int) for item in guild_ids) and guild_ids is not []: + raise error.IncorrectGuildIDType( + f"The snowflake IDs {guild_ids} given are not a list of integers. Because of discord.py convention, please use integer IDs instead. Furthermore, the command '{name}' will be deactivated and broken until fixed." + ) if base in self.commands: for x in guild_ids: @@ -727,6 +736,7 @@ def wrapper(cmd): permissions, connector, ) + return obj return wrapper @@ -825,6 +835,7 @@ def wrapper(cmd): options, connector, ) + return obj return wrapper diff --git a/discord_slash/cog_ext.py b/discord_slash/cog_ext.py index 54e699f1f..7f3f9c75e 100644 --- a/discord_slash/cog_ext.py +++ b/discord_slash/cog_ext.py @@ -1,6 +1,7 @@ import inspect import typing +from .error import IncorrectGuildIDType from .model import CogBaseCommandObject, CogSubcommandObject from .utils import manage_commands @@ -13,7 +14,7 @@ def cog_slash( options: typing.List[dict] = None, default_permission: bool = True, permissions: typing.Dict[int, list] = None, - connector: dict = None + connector: dict = None, ): """ Decorator for Cog to add slash command.\n @@ -54,6 +55,12 @@ def wrapper(cmd): else: opts = options + if guild_ids is not None: + if not all(isinstance(item, int) for item in guild_ids): + raise IncorrectGuildIDType( + f"The snowflake IDs {guild_ids} given are not a list of integers. Because of discord.py convention, please use integer IDs instead. Furthermore, the command '{name or cmd.__name__}' will be deactivated and broken until fixed." + ) + _cmd = { "func": cmd, "description": desc, @@ -83,7 +90,7 @@ def cog_subcommand( sub_group_desc: str = None, guild_ids: typing.List[int] = None, options: typing.List[dict] = None, - connector: dict = None + connector: dict = None, ): """ Decorator for Cog to add subcommand.\n @@ -137,6 +144,12 @@ def wrapper(cmd): else: opts = options + if guild_ids is not None: + if not all(isinstance(item, int) for item in guild_ids): + raise IncorrectGuildIDType( + f"The snowflake IDs {guild_ids} given are not a list of integers. Because of discord.py convention, please use integer IDs instead. Furthermore, the command '{name or cmd.__name__}' will be deactivated and broken until fixed." + ) + _cmd = { "func": None, "description": base_description, diff --git a/discord_slash/error.py b/discord_slash/error.py index 897576281..30e6041ed 100644 --- a/discord_slash/error.py +++ b/discord_slash/error.py @@ -58,6 +58,12 @@ class IncorrectType(SlashCommandError): """ +class IncorrectGuildIDType(SlashCommandError): + """ + Guild ID type passed was incorrect + """ + + class IncorrectCommandData(SlashCommandError): """ Incorrect data was passed to a slash command data object