35
35
)
36
36
37
37
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
+ """
38
57
def __init__ (self , id : Union [int , str ], type : int , permission : bool = True , guild_id : int = None ):
39
58
self .id = id
40
59
self .type = type
@@ -45,6 +64,27 @@ def to_dict(self) -> Dict[str, Union[int, bool]]:
45
64
return {"id" : self .id , "type" : self .type , "permission" : self .permission }
46
65
47
66
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
+ """
48
88
def decorator (func : Callable ):
49
89
if not role_id is None :
50
90
app_cmd_perm = Permission (role_id , 1 , permission , guild_id )
@@ -65,6 +105,21 @@ def decorator(func: Callable):
65
105
return decorator
66
106
67
107
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
+ """
68
123
def decorator (func : Callable ):
69
124
# Create __app_cmd_perms__
70
125
if not hasattr (func , '__app_cmd_perms__' ):
@@ -81,6 +136,22 @@ def decorator(func: Callable):
81
136
return decorator
82
137
83
138
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
+ """
84
155
def decorator (func : Callable ):
85
156
# Create __app_cmd_perms__
86
157
if not hasattr (func , '__app_cmd_perms__' ):
@@ -98,6 +169,20 @@ def decorator(func: Callable):
98
169
return decorator
99
170
100
171
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
+ """
101
186
def decorator (func : Callable ):
102
187
# Create __app_cmd_perms__
103
188
if not hasattr (func , '__app_cmd_perms__' ):
@@ -114,6 +199,19 @@ def decorator(func: Callable):
114
199
return decorator
115
200
116
201
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
+ """
117
215
def decorator (func : Callable ):
118
216
# Create __app_cmd_perms__
119
217
if not hasattr (func , '__app_cmd_perms__' ):
@@ -127,4 +225,4 @@ def decorator(func: Callable):
127
225
128
226
return func
129
227
130
- return decorator
228
+ return decorator
0 commit comments