Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Warnings] AllowCustomReasons -> This is not a registered reason
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

warn

#### What cog is this command from?

warnings

#### What were you expecting to happen?

A user to be warned with whatever reason I just specified

#### What actually happened?

Error message: "That is not a registered reason!"

#### How can we reproduce this issue?

1. Enable custom reasons `[p]warningset allowcustomreasons 1`/true/yes
2. Warn a user with a custom reason: `[p]warn <user> <reason>`
3. "That is not a registered reason!"

------

I've asked about this on multiple beta versions and still didn't get a clear reply if this is supposed to work how I think it is. At least I can't figure out why else there would be a subcommand called "allowcustomreasons". If this is supposed to do something else, can you clarify that somehow in the command help? Because I interpret this that when allowcustomreasons is disabled, you can only use added reasons on the warn, and when it's enabled you can specify any reason.


Discussion:
You have a valid point, it could be clearer how to use custom reasons.

To specify a custom reason, use `[p]warn <user> custom` and the bot will ask you to enter the reason, along with some other stuff I believe.

To make it more user-friendly, perhaps when custom reasons are enabled, changing the message "That is not a registered reason!" to "That is not a registered reason! To specify a custom reason, put `custom` for the reason."?
Right, apparently I have not read the output of `[p]help warn` with both sides of my brain active, it clearly says there about using "custom". Big oof!

However, I do like the clarification idea on the error message! Always good to have error messages spell stuff out for dumbos like me 😅 
Now that I know how it works, I tested it and the DM was sent fine, however no modlog event was created.

Is this caused by the rework #1867?
I have the warning case enabled on modlog, and since the case is still there it's still supposed to add a modlog event on warn, yes?

So either something is wrong with the case creation or then the case for warnings is not supposed to be there. Didn't want to create a separate issue for this, not sure if I should?

(B19 btw)
@Mystard I'd appreciate it if you opened a new issue for that one, thanks :)

Resolving patch:
diff --git a/redbot/cogs/warnings/warnings.py b/redbot/cogs/warnings/warnings.py
--- a/redbot/cogs/warnings/warnings.py
+++ b/redbot/cogs/warnings/warnings.py
@@ -221,8 +221,8 @@ async def warn(self, ctx: commands.Context, user: discord.Member, reason: str):
         if user == ctx.author:
             await ctx.send(_("You cannot warn yourself."))
             return
+        custom_allowed = await self.config.guild(ctx.guild).allow_custom_reasons()
         if reason.lower() == "custom":
-            custom_allowed = await self.config.guild(ctx.guild).allow_custom_reasons()
             if not custom_allowed:
                 await ctx.send(
                     _(
@@ -236,7 +236,21 @@ async def warn(self, ctx: commands.Context, user: discord.Member, reason: str):
             guild_settings = self.config.guild(ctx.guild)
             async with guild_settings.reasons() as registered_reasons:
                 if reason.lower() not in registered_reasons:
-                    await ctx.send(_("That is not a registered reason!"))
+                    msg = _("That is not a registered reason!")
+                    if custom_allowed:
+                        msg += " " + _(
+                            "Do `{prefix}warn {user} custom` to specify a custom reason."
+                        ).format(prefix=ctx.prefix, user=ctx.author)
+                    elif (
+                        ctx.guild.owner == ctx.author
+                        or ctx.channel.permissions_for(ctx.author).administrator
+                        or await ctx.bot.is_owner(ctx.author)
+                    ):
+                        msg += " " + _(
+                            "Do `{prefix}warningset allowcustomreasons true` to enable custom "
+                            "reasons."
+                        ).format(prefix=ctx.prefix)
+                    await ctx.send(msg)
                     return
                 else:
                     reason_type = registered_reasons[reason.lower()]


Test patch: