[Modlog]Raise error instead of failing silently on invalid arguments (#5386)

Co-authored-by: Dav <dav@mail.stopdavabuse.de>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
Dav
2023-03-18 22:31:28 +01:00
committed by GitHub
parent 2ab204438e
commit 7c7e5edb19
2 changed files with 14 additions and 4 deletions

View File

@@ -1020,18 +1020,23 @@ async def create_case(
Raises
------
ValueError
If the action type is not a valid action type.
RuntimeError
If user is the bot itself.
TypeError
If ``channel`` is of type `discord.PartialMessageable`.
"""
case_type = await get_casetype(action_type, guild)
if case_type is None:
return
raise ValueError(f"{action_type} is not a valid action type.")
if not await case_type.is_enabled():
return
if user == bot.user:
return
user_id = user if isinstance(user, int) else user.id
if user_id == bot.user.id:
raise RuntimeError("The bot itself can not be the target of a modlog entry.")
if isinstance(channel, discord.PartialMessageable):
raise TypeError("Can't use PartialMessageable as the channel for a modlog case.")