File tree Expand file tree Collapse file tree 1 file changed +41
-4
lines changed Expand file tree Collapse file tree 1 file changed +41
-4
lines changed Original file line number Diff line number Diff line change 1
1
from discord .ext import commands
2
2
3
+
3
4
def has_permissions (** perms ):
4
- """Check if the author has required permissions.
5
- This will always return ``True`` if the author is a bot owner, or
6
- has the ``administrator`` permission.
7
5
"""
6
+ A decorator that checks if the author has the required permissions.
7
+
8
+ Examples
9
+ --------
10
+ @has_permissions(administrator=True)
11
+ async def setup(ctx):
12
+ print("Success")
13
+ """
14
+
8
15
async def predicate (ctx ):
16
+ """
17
+ Parameters
18
+ ----------
19
+ ctx : Context
20
+ The current discord.py `Context`.
21
+
22
+ Returns
23
+ -------
24
+ True
25
+ If the author is a bot owner, or
26
+ has the ``administrator`` permission.
27
+ Or if the author has all of the required permissions.
28
+ Otherwise, `False`.
29
+ """
9
30
if await ctx .bot .is_owner (ctx .author ):
10
31
return True
11
32
@@ -20,7 +41,23 @@ async def predicate(ctx):
20
41
21
42
22
43
def thread_only ():
23
- """Checks if the command is being run in a modmail thread"""
44
+ """
45
+ A decorator that checks if the command
46
+ is being ran within a Modmail thread.
47
+ """
48
+
24
49
async def predicate (ctx ):
50
+ """
51
+ Parameters
52
+ ----------
53
+ ctx : Context
54
+ The current discord.py `Context`.
55
+
56
+ Returns
57
+ -------
58
+ True
59
+ if the current `Context` is within a Modmail thread.
60
+ Otherwise, `False`.
61
+ """
25
62
return ctx .thread is not None
26
63
return commands .check (predicate )
You can’t perform that action at this time.
0 commit comments