Skip to content

Commit ee983e6

Browse files
authored
Merge pull request #176 from benwoo1110/permission-fixes
Permission fixes
2 parents 00e563c + 8d364a5 commit ee983e6

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

discord_slash/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def add_slash_command(self,
441441
guild_ids: typing.List[int] = None,
442442
options: list = None,
443443
default_permission: bool = True,
444-
permissions: dict = None,
444+
permissions: typing.Dict[int, list] = None,
445445
connector: dict = None,
446446
has_subcommands: bool = False):
447447
"""
@@ -463,7 +463,7 @@ def add_slash_command(self,
463463
:type options: list
464464
:param default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``.
465465
:type default_permission: bool
466-
:param permissions: Permission requirements of the slash command. Default ``None``.
466+
: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``.
467467
:type permissions: dict
468468
:param connector: Kwargs connector for the command. Default ``None``.
469469
:type connector: dict
@@ -510,7 +510,7 @@ def add_subcommand(self,
510510
description: str = None,
511511
base_description: str = None,
512512
base_default_permission: bool = True,
513-
base_permissions: dict = None,
513+
base_permissions: typing.Dict[int, list] = None,
514514
subcommand_group_description: str = None,
515515
guild_ids: typing.List[int] = None,
516516
options: list = None,
@@ -532,8 +532,8 @@ def add_subcommand(self,
532532
:type base_description: str
533533
:param default_permission: Sets if users have permission to run base command by default, when no permissions are set. Default ``True``.
534534
:type default_permission: bool
535-
:param permissions: Permission requirements of the base command. Default ``None``.
536-
:type permissions: dict
535+
: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``.
536+
:type base_permissions: dict
537537
:param subcommand_group_description: Description of the subcommand_group. Default ``None``.
538538
:type subcommand_group_description: str
539539
:param guild_ids: List of guild ID of where the command will be used. Default ``None``, which will be global command.

discord_slash/cog_ext.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def cog_slash(*,
1010
guild_ids: typing.List[int] = None,
1111
options: typing.List[dict] = None,
1212
default_permission: bool = True,
13-
permissions: dict = None,
13+
permissions: typing.Dict[int, list] = None,
1414
connector: dict = None):
1515
"""
1616
Decorator for Cog to add slash command.\n
@@ -38,7 +38,7 @@ async def ping(self, ctx: SlashContext):
3838
:type options: List[dict]
3939
:param default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``.
4040
:type default_permission: bool
41-
:param permissions: Permission requirements of the slash command. Default ``None``.
41+
: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``.
4242
:type permissions: dict
4343
:param connector: Kwargs connector for the command. Default ``None``.
4444
:type connector: dict
@@ -72,7 +72,7 @@ def cog_subcommand(*,
7272
base_description: str = None,
7373
base_desc: str = None,
7474
base_default_permission: bool = True,
75-
base_permissions: dict = None,
75+
base_permissions: typing.Dict[int, list] = None,
7676
subcommand_group_description: str = None,
7777
sub_group_desc: str = None,
7878
guild_ids: typing.List[int] = None,
@@ -107,7 +107,7 @@ async def group_say(self, ctx: SlashContext, text: str):
107107
:param base_desc: Alias of ``base_description``.
108108
:param base_default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``.
109109
:type base_default_permission: bool
110-
:param base_permissions: Permission requirements of the slash command. Default ``None``.
110+
: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``.
111111
:type base_permissions: dict
112112
:param subcommand_group_description: Description of the subcommand_group. Default ``None``.
113113
:type subcommand_group_description: str

discord_slash/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def __init__(self, name, cmd): # Let's reuse old command formatting.
195195
super().__init__(name, cmd)
196196
self.has_subcommands = cmd["has_subcommands"]
197197
self.default_permission = cmd["default_permission"]
198-
self.permissions = cmd["api_permissions"] or []
198+
self.permissions = cmd["api_permissions"] or {}
199199

200200

201201
class SubcommandObject(CommandObject):

docs/gettingstarted.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ This is an example of how a single permission will look when represented as a js
269269
"permission": True
270270
}
271271
272-
Now, let take a look simple example. The slash command decorator have a permissions parameter Where
273-
it takes in a dictionary. The key being the guild to apply permissions on, and value being the list
272+
Now, let take a look at an example. The slash command decorator have a permissions parameter where
273+
it takes in a dictionary. The key being the guild id to apply permissions on, and value being the list
274274
of permissions to apply. For each permission, we can use the handy ``create_permission`` method to
275275
build the permission json explain above.
276276

@@ -280,7 +280,7 @@ role with id ``99999999`` and disallowing user with id ``88888888`` from running
280280
.. code-block:: python
281281
282282
from discord_slash.utils.manage_commands import create_permission
283-
from discord_slash.model import SubcommandApplicationPermissionType
283+
from discord_slash.model import SlashCommandPermissionType
284284
285285
@slash.slash(name="test",
286286
description="This is just a test command, nothing more.",
@@ -293,17 +293,18 @@ role with id ``99999999`` and disallowing user with id ``88888888`` from running
293293
async def test(ctx):
294294
await ctx.send(content="Hello World!")
295295
296-
Alternatively you can use the ``@slash.permission`` decorator to define your guild permissions for the command.
296+
Alternatively, you can use the ``@slash.permission`` decorator to define your guild permissions for the
297+
command as show in the following example:
297298

298299
.. code-block:: python
299300
300301
from discord_slash.utils.manage_commands import create_permission
301-
from discord_slash.model import SubcommandApplicationPermissionType
302+
from discord_slash.model import SlashCommandPermissionType
302303
303304
@slash.slash(name="test",
304305
description="This is just a test command, nothing more.")
305-
@slash.permission(guild_id = 12345678,
306-
permission = [
306+
@slash.permission(guild_id=12345678,
307+
permissions=[
307308
create_permission(99999999, SlashCommandPermissionType.ROLE, True),
308309
create_permission(88888888, SlashCommandPermissionType.USER, False)
309310
])

0 commit comments

Comments
 (0)