Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- [discord-api-docs Community Resources: Interactions](https://discord.com/developers/docs/topics/community-resources#interactions)

11 changes: 11 additions & 0 deletions discord_slash/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -727,6 +736,7 @@ def wrapper(cmd):
permissions,
connector,
)

return obj

return wrapper
Expand Down Expand Up @@ -825,6 +835,7 @@ def wrapper(cmd):
options,
connector,
)

return obj

return wrapper
Expand Down
17 changes: 15 additions & 2 deletions discord_slash/cog_ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import typing

from .error import IncorrectGuildIDType
from .model import CogBaseCommandObject, CogSubcommandObject
from .utils import manage_commands

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions discord_slash/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down