mirror of
https://github.com/uhIgnacio/EmoteManager.git
synced 2024-08-15 02:23:13 +00:00
fix command error handling
so, i had a fundamental misunderstanding about how command errors work. turns out the help command runs the checks for each function. This ended up sending one "permission denied" message for each command in the Emotes cog, *each time help was run*. To fix this, __local_check needs to not have extra side effects. I create one new exception, MissingManageServerEmojis, and raise it in case the user or bot is missing permissions. I re-use NoPrivateMessages, since that's already a d.py exception. Then I catch the errors in on_command_error, and send them to the user.
This commit is contained in:
parent
52618915be
commit
c5c6e7ef24
2 changed files with 20 additions and 16 deletions
|
@ -48,26 +48,25 @@ class Emotes:
|
|||
|
||||
async def __local_check(self, context):
|
||||
if not context.guild:
|
||||
await context.send(
|
||||
f'{utils.SUCCESS_EMOTES[False]} Sorry, this command may only be used in a server.')
|
||||
raise commands.NoPrivateMessage
|
||||
return False
|
||||
|
||||
if (
|
||||
not context.author.guild_permissions.manage_emojis
|
||||
or not context.guild.me.guild_permissions.manage_emojis
|
||||
):
|
||||
await context.send(
|
||||
f'{utils.SUCCESS_EMOTES[False]} '
|
||||
"Sorry, you don't have enough permissions to run this command. "
|
||||
'You and I both need the Manage Emojis permission.')
|
||||
return False
|
||||
raise errors.MissingManageEmojisPermission
|
||||
|
||||
return True
|
||||
|
||||
async def on_command_error(self, context, error):
|
||||
if isinstance(error, errors.EmoteManagerError):
|
||||
if isinstance(error, (errors.EmoteManagerError, errors.MissingManageEmojisPermission)):
|
||||
await context.send(str(error))
|
||||
|
||||
if isinstance(error, commands.NoPrivateMessage):
|
||||
await context.send(
|
||||
f'{utils.SUCCESS_EMOTES[False]} Sorry, this command may only be used in a server.')
|
||||
|
||||
@commands.command()
|
||||
async def add(self, context, *args):
|
||||
"""Add a new emote to this server.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue