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
10 changes: 5 additions & 5 deletions discord_slash/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def add_slash_command(self,
guild_ids: typing.List[int] = None,
options: list = None,
default_permission: bool = True,
permissions: dict = None,
permissions: typing.Dict[int, list] = None,
connector: dict = None,
has_subcommands: bool = False):
"""
Expand All @@ -463,7 +463,7 @@ def add_slash_command(self,
:type options: list
:param default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``.
:type default_permission: bool
:param permissions: Permission requirements of the slash command. Default ``None``.
:param permissions: Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default ``None``.
:type permissions: dict
:param connector: Kwargs connector for the command. Default ``None``.
:type connector: dict
Expand Down Expand Up @@ -510,7 +510,7 @@ def add_subcommand(self,
description: str = None,
base_description: str = None,
base_default_permission: bool = True,
base_permissions: dict = None,
base_permissions: typing.Dict[int, list] = None,
subcommand_group_description: str = None,
guild_ids: typing.List[int] = None,
options: list = None,
Expand All @@ -532,8 +532,8 @@ def add_subcommand(self,
:type base_description: str
:param default_permission: Sets if users have permission to run base command by default, when no permissions are set. Default ``True``.
:type default_permission: bool
:param permissions: Permission requirements of the base command. Default ``None``.
:type permissions: dict
:param base_permissions: Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default ``None``.
:type base_permissions: dict
:param subcommand_group_description: Description of the subcommand_group. Default ``None``.
:type subcommand_group_description: str
:param guild_ids: List of guild ID of where the command will be used. Default ``None``, which will be global command.
Expand Down
8 changes: 4 additions & 4 deletions discord_slash/cog_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def cog_slash(*,
guild_ids: typing.List[int] = None,
options: typing.List[dict] = None,
default_permission: bool = True,
permissions: dict = None,
permissions: typing.Dict[int, list] = None,
connector: dict = None):
"""
Decorator for Cog to add slash command.\n
Expand Down Expand Up @@ -38,7 +38,7 @@ async def ping(self, ctx: SlashContext):
:type options: List[dict]
:param default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``.
:type default_permission: bool
:param permissions: Permission requirements of the slash command. Default ``None``.
:param permissions: Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default ``None``.
:type permissions: dict
:param connector: Kwargs connector for the command. Default ``None``.
:type connector: dict
Expand Down Expand Up @@ -72,7 +72,7 @@ def cog_subcommand(*,
base_description: str = None,
base_desc: str = None,
base_default_permission: bool = True,
base_permissions: dict = None,
base_permissions: typing.Dict[int, list] = None,
subcommand_group_description: str = None,
sub_group_desc: str = None,
guild_ids: typing.List[int] = None,
Expand Down Expand Up @@ -107,7 +107,7 @@ async def group_say(self, ctx: SlashContext, text: str):
:param base_desc: Alias of ``base_description``.
:param base_default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``.
:type base_default_permission: bool
:param base_permissions: Permission requirements of the slash command. Default ``None``.
:param base_permissions: Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default ``None``.
:type base_permissions: dict
:param subcommand_group_description: Description of the subcommand_group. Default ``None``.
:type subcommand_group_description: str
Expand Down
2 changes: 1 addition & 1 deletion discord_slash/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def __init__(self, name, cmd): # Let's reuse old command formatting.
super().__init__(name, cmd)
self.has_subcommands = cmd["has_subcommands"]
self.default_permission = cmd["default_permission"]
self.permissions = cmd["api_permissions"] or []
self.permissions = cmd["api_permissions"] or {}


class SubcommandObject(CommandObject):
Expand Down
15 changes: 8 additions & 7 deletions docs/gettingstarted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ This is an example of how a single permission will look when represented as a js
"permission": True
}

Now, let take a look simple example. The slash command decorator have a permissions parameter Where
it takes in a dictionary. The key being the guild to apply permissions on, and value being the list
Now, let take a look at an example. The slash command decorator have a permissions parameter where
it takes in a dictionary. The key being the guild id to apply permissions on, and value being the list
of permissions to apply. For each permission, we can use the handy ``create_permission`` method to
build the permission json explain above.

Expand All @@ -280,7 +280,7 @@ role with id ``99999999`` and disallowing user with id ``88888888`` from running
.. code-block:: python

from discord_slash.utils.manage_commands import create_permission
from discord_slash.model import SubcommandApplicationPermissionType
from discord_slash.model import SlashCommandPermissionType

@slash.slash(name="test",
description="This is just a test command, nothing more.",
Expand All @@ -293,17 +293,18 @@ role with id ``99999999`` and disallowing user with id ``88888888`` from running
async def test(ctx):
await ctx.send(content="Hello World!")

Alternatively you can use the ``@slash.permission`` decorator to define your guild permissions for the command.
Alternatively, you can use the ``@slash.permission`` decorator to define your guild permissions for the
command as show in the following example:

.. code-block:: python

from discord_slash.utils.manage_commands import create_permission
from discord_slash.model import SubcommandApplicationPermissionType
from discord_slash.model import SlashCommandPermissionType

@slash.slash(name="test",
description="This is just a test command, nothing more.")
@slash.permission(guild_id = 12345678,
permission = [
@slash.permission(guild_id=12345678,
permissions=[
create_permission(99999999, SlashCommandPermissionType.ROLE, True),
create_permission(88888888, SlashCommandPermissionType.USER, False)
])
Expand Down