Skip to content

Commit d8af5f4

Browse files
committed
More intuitive message for check failures
1 parent b2a8e49 commit d8af5f4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

bot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ async def on_command_error(self, context, exception):
781781
command=str(context.command))
782782
elif isinstance(exception, commands.CommandNotFound):
783783
logger.warning(error('CommandNotFound: ' + str(exception)))
784+
elif isinstance(exception, commands.CheckFailure):
785+
logger.warning(error('CheckFailure: ' + str(exception)))
784786
else:
785787
logger.error(error('Unexpected exception:'), exc_info=exception)
786788

@@ -915,6 +917,7 @@ async def autoupdate_loop(self):
915917

916918
await asyncio.sleep(3600)
917919

920+
918921
if __name__ == '__main__':
919922
if os.name != 'nt':
920923
import uvloop

core/checks.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import logging
12
from discord.ext import commands
3+
from core.utils import error
4+
5+
logger = logging.getLogger('Modmail')
26

37

48
def has_permissions(**perms):
@@ -33,11 +37,17 @@ async def predicate(ctx):
3337

3438
resolved = ctx.channel.permissions_for(ctx.author)
3539

36-
return resolved.administrator or all(
40+
has_perm = resolved.administrator or all(
3741
getattr(resolved, name, None) == value
3842
for name, value in perms.items()
3943
)
4044

45+
if not has_perm:
46+
restrictions = ', '.join(f'{name.replace("_", " ").title()} ({"yes" if value else "no"})'
47+
for name, value in perms.items())
48+
logger.error(error(f'Command `{ctx.command.qualified_name}` processes '
49+
f'the following restrictions(s): {restrictions}.'))
50+
return has_perm
4151
return commands.check(predicate)
4252

4353

0 commit comments

Comments
 (0)