Skip to content

Commit 33a1567

Browse files
committed
Add custom checks for permissions
1 parent 2a12a8f commit 33a1567

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

core/checks.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from discord.ext import commands
2+
3+
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+
"""
8+
async def predicate(ctx):
9+
if await ctx.bot.is_owner(ctx.author):
10+
return True
11+
12+
resolved = ctx.channel.permissions_for(ctx.author)
13+
14+
return resolved.administrator or all(
15+
getattr(resolved, name, None) == value for name, value in perms.items()
16+
)
17+
18+
return commands.check(predicate)
19+
20+
def thread_only():
21+
"""Checks if the command is being run in a modmail thread"""
22+
async def predicate(ctx):
23+
return ctx.thread is not None
24+
return commands.check(predicate)

0 commit comments

Comments
 (0)