Skip to content

Commit cc0d4d3

Browse files
authored
Merge pull request #412 from EnokiUN/master
Docstrings for application command permissions
2 parents d90ffe2 + 1fb9a84 commit cc0d4d3

File tree

1 file changed

+99
-1
lines changed

1 file changed

+99
-1
lines changed

discord/commands/permissions.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@
3535
)
3636

3737
class Permission:
38+
"""The class used in the application command decorators
39+
to hash permission data into a dictionary using the
40+
:meth:`to_dict` method to be sent to the discord API later on.
41+
42+
.. versionadded:: 2.0
43+
44+
Attributes
45+
-----------
46+
id: Union[:class:`int`, :class:`str`]
47+
A string or integer that represents or helps get
48+
the id of the user or role that the permission is tied to.
49+
type: :class:`int`
50+
An integer representing the type of the permission.
51+
permission: :class:`bool`
52+
A boolean representing the permission's value.
53+
guild_id: :class:`int`
54+
The integer which represents the id of the guild that the
55+
permission may be tied to.
56+
"""
3857
def __init__(self, id: Union[int, str], type: int, permission: bool = True, guild_id: int = None):
3958
self.id = id
4059
self.type = type
@@ -45,6 +64,27 @@ def to_dict(self) -> Dict[str, Union[int, bool]]:
4564
return {"id": self.id, "type": self.type, "permission": self.permission}
4665

4766
def permission(role_id: int = None, user_id: int = None, permission: bool = True, guild_id: int = None):
67+
"""The method used to specify application command permissions
68+
for specific users or roles using their id.
69+
70+
This method is meant to be used as a decorator.
71+
72+
.. versionadded:: 2.0
73+
74+
Parameters
75+
-----------
76+
role_id: :class:`int`
77+
An integer which represents the id of the role that the
78+
permission may be tied to.
79+
user_id: :class:`int`
80+
An integer which represents the id of the user that the
81+
permission may be tied to.
82+
permission: :class:`bool`
83+
A boolean representing the permission's value.
84+
guild_id: :class:`int`
85+
The integer which represents the id of the guild that the
86+
permission may be tied to.
87+
"""
4888
def decorator(func: Callable):
4989
if not role_id is None:
5090
app_cmd_perm = Permission(role_id, 1, permission, guild_id)
@@ -65,6 +105,21 @@ def decorator(func: Callable):
65105
return decorator
66106

67107
def has_role(item: Union[int, str], guild_id: int = None):
108+
"""The method used to specify application command role restrictions.
109+
110+
This method is meant to be used as a decorator.
111+
112+
.. versionadded:: 2.0
113+
114+
Parameters
115+
-----------
116+
item: Union[:class:`int`, :class:`str`]
117+
An integer or string that represent the id or name of the role
118+
that the permission is tied to.
119+
guild_id: :class:`int`
120+
The integer which represents the id of the guild that the
121+
permission may be tied to.
122+
"""
68123
def decorator(func: Callable):
69124
# Create __app_cmd_perms__
70125
if not hasattr(func, '__app_cmd_perms__'):
@@ -81,6 +136,22 @@ def decorator(func: Callable):
81136
return decorator
82137

83138
def has_any_role(*items: Union[int, str], guild_id: int = None):
139+
"""The method used to specify multiple application command role restrictions,
140+
The application command runs if the invoker has **any** of the specified roles.
141+
142+
This method is meant to be used as a decorator.
143+
144+
.. versionadded:: 2.0
145+
146+
Parameters
147+
-----------
148+
*items: Union[:class:`int`, :class:`str`]
149+
The integers or strings that represent the ids or names of the roles
150+
that the permission is tied to.
151+
guild_id: :class:`int`
152+
The integer which represents the id of the guild that the
153+
permission may be tied to.
154+
"""
84155
def decorator(func: Callable):
85156
# Create __app_cmd_perms__
86157
if not hasattr(func, '__app_cmd_perms__'):
@@ -98,6 +169,20 @@ def decorator(func: Callable):
98169
return decorator
99170

100171
def is_user(user: int, guild_id: int = None):
172+
"""The method used to specify application command user restrictions.
173+
174+
This method is meant to be used as a decorator.
175+
176+
.. versionadded:: 2.0
177+
178+
Parameters
179+
-----------
180+
user: :class:`int`
181+
An integer that represent the id of the user that the permission is tied to.
182+
guild_id: :class:`int`
183+
The integer which represents the id of the guild that the
184+
permission may be tied to.
185+
"""
101186
def decorator(func: Callable):
102187
# Create __app_cmd_perms__
103188
if not hasattr(func, '__app_cmd_perms__'):
@@ -114,6 +199,19 @@ def decorator(func: Callable):
114199
return decorator
115200

116201
def is_owner(guild_id: int = None):
202+
"""The method used to limit application commands exclusively
203+
to the owner of the bot.
204+
205+
This method is meant to be used as a decorator.
206+
207+
.. versionadded:: 2.0
208+
209+
Parameters
210+
-----------
211+
guild_id: :class:`int`
212+
The integer which represents the id of the guild that the
213+
permission may be tied to.
214+
"""
117215
def decorator(func: Callable):
118216
# Create __app_cmd_perms__
119217
if not hasattr(func, '__app_cmd_perms__'):
@@ -127,4 +225,4 @@ def decorator(func: Callable):
127225

128226
return func
129227

130-
return decorator
228+
return decorator

0 commit comments

Comments
 (0)