Skip to content

Commit

Permalink
[Automod] Improve error message for rule create
Browse files Browse the repository at this point in the history
  • Loading branch information
TrustyJAID committed Jul 3, 2024
1 parent 3363c48 commit 3c78488
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion automod/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,29 @@ async def create_automod_rule(
Will create an automod rule with the saved trigger `mytrigger` and
the saved actions `timeoutuser` and `notifymods`.
"""
if not name:
await ctx.send_help()
return
log.debug(f"{rule.to_args()}")
if not rule.trigger:
await ctx.send("No trigger was provided for the rule.")
return
rule_args = rule.to_args()
name = name.lower()
if rule_args.get("reason") is not None:
rule_args["reason"] = f"Created by {ctx.author}\n" + rule_args["reason"]
try:
rule = await ctx.guild.create_automod_rule(name=name, **rule_args)
except Exception as e:
await ctx.send(e)
rule_args_str = "\n".join(f"- {k}: {v}" for k, v in rule_args.items())
await ctx.send(
(
"There was an error creating a rule with the following rules:\n"
f"Error: {e}\n"
f"Name: {name}\n"
f"Rules:\n{rule_args_str}"
)
)
return
pages = AutoModRulePages([rule], guild=ctx.guild)
await BaseMenu(pages, self).start(ctx)
Expand Down

0 comments on commit 3c78488

Please sign in to comment.