From 53f4f2838d0648f78bc8d48f5ad537cb8e91547e Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sat, 24 Jul 2021 20:55:23 -0600 Subject: [PATCH] Fix ban command to not error on failed DM --- jarvis/__init__.py | 2 +- jarvis/cogs/admin.py | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index 772cf7d..bbb703d 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -44,7 +44,7 @@ jarvis = commands.Bot( ) slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True) jarvis_self = Process() -__version__ = "1.5.4" +__version__ = "1.5.5" db = DBManager(get_config().mongo).mongo diff --git a/jarvis/cogs/admin.py b/jarvis/cogs/admin.py index 79e70d1..ac68e94 100644 --- a/jarvis/cogs/admin.py +++ b/jarvis/cogs/admin.py @@ -14,8 +14,18 @@ from discord_slash.utils.manage_commands import create_choice, create_option import jarvis from jarvis.db import DBManager -from jarvis.db.types import (Autopurge, Ban, Kick, Lock, MongoSort, Mute, - Purge, Setting, Unban, Warning) +from jarvis.db.types import ( + Autopurge, + Ban, + Kick, + Lock, + MongoSort, + Mute, + Purge, + Setting, + Unban, + Warning, +) from jarvis.utils import build_embed from jarvis.utils.field import Field from jarvis.utils.permissions import admin_or_permissions @@ -131,13 +141,22 @@ class AdminCog(commands.Cog): except Exception as e: await ctx.send(f"Failed to ban user:\n```\n{e}\n```", hidden=True) return - await user.send(user_message) + send_failed = False + try: + await user.send(user_message) + except Exception: + send_failed = True if mtype == "soft": await ctx.guild.unban(user, reason="Ban was softban") - await ctx.send( + + message = ( f"{user.name} has been {mtype}banned from {guild_name}." + f" Reason:\n{reason}" ) + + if send_failed: + message += "\n**Note: DM failed to send to user.**" + await ctx.send(message) if type != "temp": duration = None active = True