Skip to content

Commit a807e9a

Browse files
authored
Merge pull request #662 from Dorukyum/commandpermission
Rename Permission to CommandPermission
2 parents 5263a4d + cf28c9f commit a807e9a

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

discord/commands/commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from .context import ApplicationContext, AutocompleteContext
3737
from .errors import ApplicationCommandError, CheckFailure, ApplicationCommandInvokeError
38-
from .permissions import Permission
38+
from .permissions import CommandPermission
3939
from ..enums import SlashCommandOptionType, ChannelType
4040
from ..errors import ValidationError, ClientException
4141
from ..member import Member
@@ -355,7 +355,7 @@ class SlashCommand(ApplicationCommand):
355355
isn't one.
356356
default_permission: :class:`bool`
357357
Whether the command is enabled by default when it is added to a guild.
358-
permissions: List[:class:`Permission`]
358+
permissions: List[:class:`CommandPermission`]
359359
The permissions for this command.
360360
361361
.. note::
@@ -420,7 +420,7 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
420420

421421
# Permissions
422422
self.default_permission = kwargs.get("default_permission", True)
423-
self.permissions: List[Permission] = getattr(func, "__app_cmd_perms__", []) + kwargs.get("permissions", [])
423+
self.permissions: List[CommandPermission] = getattr(func, "__app_cmd_perms__", []) + kwargs.get("permissions", [])
424424
if self.permissions and self.default_permission:
425425
self.default_permission = False
426426

@@ -800,7 +800,7 @@ def __init__(
800800

801801
# Permissions
802802
self.default_permission = kwargs.get("default_permission", True)
803-
self.permissions: List[Permission] = kwargs.get("permissions", [])
803+
self.permissions: List[CommandPermission] = kwargs.get("permissions", [])
804804
if self.permissions and self.default_permission:
805805
self.default_permission = False
806806

discord/commands/permissions.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
from typing import Union, Dict, Callable
2727

2828
__all__ = (
29-
"Permission",
29+
"CommandPermission",
3030
"has_role",
3131
"has_any_role",
3232
"is_user",
3333
"is_owner",
3434
"permission",
3535
)
3636

37-
class Permission:
37+
class CommandPermission:
3838
"""The class used in the application command decorators
3939
to hash permission data into a dictionary using the
4040
:meth:`to_dict` method to be sent to the discord API later on.
@@ -87,9 +87,9 @@ def permission(role_id: int = None, user_id: int = None, permission: bool = True
8787
"""
8888
def decorator(func: Callable):
8989
if not role_id is None:
90-
app_cmd_perm = Permission(role_id, 1, permission, guild_id)
90+
app_cmd_perm = CommandPermission(role_id, 1, permission, guild_id)
9191
elif not user_id is None:
92-
app_cmd_perm = Permission(user_id, 2, permission, guild_id)
92+
app_cmd_perm = CommandPermission(user_id, 2, permission, guild_id)
9393
else:
9494
raise ValueError("role_id or user_id must be specified!")
9595

@@ -126,7 +126,7 @@ def decorator(func: Callable):
126126
func.__app_cmd_perms__ = []
127127

128128
# Permissions (Will Convert ID later in register_commands if needed)
129-
app_cmd_perm = Permission(item, 1, True, guild_id) #{"id": item, "type": 1, "permission": True}
129+
app_cmd_perm = CommandPermission(item, 1, True, guild_id) #{"id": item, "type": 1, "permission": True}
130130

131131
# Append
132132
func.__app_cmd_perms__.append(app_cmd_perm)
@@ -159,7 +159,7 @@ def decorator(func: Callable):
159159

160160
# Permissions (Will Convert ID later in register_commands if needed)
161161
for item in items:
162-
app_cmd_perm = Permission(item, 1, True, guild_id) #{"id": item, "type": 1, "permission": True}
162+
app_cmd_perm = CommandPermission(item, 1, True, guild_id) #{"id": item, "type": 1, "permission": True}
163163

164164
# Append
165165
func.__app_cmd_perms__.append(app_cmd_perm)
@@ -189,7 +189,7 @@ def decorator(func: Callable):
189189
func.__app_cmd_perms__ = []
190190

191191
# Permissions (Will Convert ID later in register_commands if needed)
192-
app_cmd_perm = Permission(user, 2, True, guild_id) #{"id": user, "type": 2, "permission": True}
192+
app_cmd_perm = CommandPermission(user, 2, True, guild_id) #{"id": user, "type": 2, "permission": True}
193193

194194
# Append
195195
func.__app_cmd_perms__.append(app_cmd_perm)
@@ -218,7 +218,7 @@ def decorator(func: Callable):
218218
func.__app_cmd_perms__ = []
219219

220220
# Permissions (Will Convert ID later in register_commands if needed)
221-
app_cmd_perm = Permission("owner", 2, True, guild_id) #{"id": "owner", "type": 2, "permission": True}
221+
app_cmd_perm = CommandPermission("owner", 2, True, guild_id) #{"id": "owner", "type": 2, "permission": True}
222222

223223
# Append
224224
func.__app_cmd_perms__.append(app_cmd_perm)

examples/app_commands/slash_cog_groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import discord
2-
from discord.commands import SlashCommandGroup, Permission
2+
from discord.commands import SlashCommandGroup, CommandPermission
33
from discord.ext import commands
44

55
bot = discord.Bot(debug_guild=..., owner_id=...) # main file
@@ -19,7 +19,7 @@ def __init__(self, bot):
1919
"secret_greetings",
2020
"Secret greetings",
2121
permissions=[
22-
Permission(
22+
CommandPermission(
2323
"owner", 2, True
2424
) # Ensures the owner_id user can access this, and no one else
2525
],

examples/app_commands/slash_perms.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
# Ex: @permissions.has_role("Admin", guild_id=GUILD_ID)
2525
# --------------------------------------------
2626
# or supply permissions directly in @bot.slash_command
27-
# @bot.slash_command(default_permission=False,
28-
# permissions=[permissions.Permission(id=ID, type=TYPE, permission=True, guild_id=GUILD_ID)])
27+
# @bot.slash_command(
28+
# default_permission=False,
29+
# permissions=[
30+
# permissions.CommandPermission(id=ID, type=TYPE, permission=True, guild_id=GUILD_ID)
31+
# ]
32+
# )
2933

3034
# Note: Please replace token, GUILD_ID, USER_ID and ROLE_NAME.
3135

@@ -78,7 +82,7 @@ async def permission_decorator(ctx):
7882
@bot.slash_command(
7983
guild_ids=[GUILD_ID],
8084
default_permission=False,
81-
permissions=[permissions.Permission(id=USER_ID, type=2, permission=True)],
85+
permissions=[permissions.CommandPermission(id=USER_ID, type=2, permission=True)],
8286
)
8387
async def permission_kwarg(ctx):
8488
"""Say hello to the author""" # the command description can be supplied as the docstring

0 commit comments

Comments
 (0)