Fix ban command to not error on failed DM
This commit is contained in:
parent
7bf5e85466
commit
53f4f2838d
2 changed files with 24 additions and 5 deletions
|
@ -44,7 +44,7 @@ jarvis = commands.Bot(
|
||||||
)
|
)
|
||||||
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
||||||
jarvis_self = Process()
|
jarvis_self = Process()
|
||||||
__version__ = "1.5.4"
|
__version__ = "1.5.5"
|
||||||
|
|
||||||
|
|
||||||
db = DBManager(get_config().mongo).mongo
|
db = DBManager(get_config().mongo).mongo
|
||||||
|
|
|
@ -14,8 +14,18 @@ from discord_slash.utils.manage_commands import create_choice, create_option
|
||||||
|
|
||||||
import jarvis
|
import jarvis
|
||||||
from jarvis.db import DBManager
|
from jarvis.db import DBManager
|
||||||
from jarvis.db.types import (Autopurge, Ban, Kick, Lock, MongoSort, Mute,
|
from jarvis.db.types import (
|
||||||
Purge, Setting, Unban, Warning)
|
Autopurge,
|
||||||
|
Ban,
|
||||||
|
Kick,
|
||||||
|
Lock,
|
||||||
|
MongoSort,
|
||||||
|
Mute,
|
||||||
|
Purge,
|
||||||
|
Setting,
|
||||||
|
Unban,
|
||||||
|
Warning,
|
||||||
|
)
|
||||||
from jarvis.utils import build_embed
|
from jarvis.utils import build_embed
|
||||||
from jarvis.utils.field import Field
|
from jarvis.utils.field import Field
|
||||||
from jarvis.utils.permissions import admin_or_permissions
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
@ -131,13 +141,22 @@ class AdminCog(commands.Cog):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.send(f"Failed to ban user:\n```\n{e}\n```", hidden=True)
|
await ctx.send(f"Failed to ban user:\n```\n{e}\n```", hidden=True)
|
||||||
return
|
return
|
||||||
await user.send(user_message)
|
send_failed = False
|
||||||
|
try:
|
||||||
|
await user.send(user_message)
|
||||||
|
except Exception:
|
||||||
|
send_failed = True
|
||||||
if mtype == "soft":
|
if mtype == "soft":
|
||||||
await ctx.guild.unban(user, reason="Ban was softban")
|
await ctx.guild.unban(user, reason="Ban was softban")
|
||||||
await ctx.send(
|
|
||||||
|
message = (
|
||||||
f"{user.name} has been {mtype}banned from {guild_name}."
|
f"{user.name} has been {mtype}banned from {guild_name}."
|
||||||
+ f" Reason:\n{reason}"
|
+ f" Reason:\n{reason}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if send_failed:
|
||||||
|
message += "\n**Note: DM failed to send to user.**"
|
||||||
|
await ctx.send(message)
|
||||||
if type != "temp":
|
if type != "temp":
|
||||||
duration = None
|
duration = None
|
||||||
active = True
|
active = True
|
||||||
|
|
Loading…
Add table
Reference in a new issue