Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3] Warn command error
# 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?

Expected a user to be warned

#### What actually happened?

User was not warned. Received both error "That is not a registered reason!" (This is a bit odd since I have allowed custom reasons) and `Error in command 'warn'. Check your console or logs for details.`

#### How can we reproduce this issue?

If I only knew. People on #1562 didn't seem to be able to.


Debian 8 Jessie, Python 3.5.3+, Red - Version 3.0.0b14, even tried updating the warning cog to the lastest version from V3/devel but no luck there either.

```
Exception in command 'warn'
Traceback (most recent call last):
  File "/home/red3/.local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/home/red3/.local/lib/python3.5/site-packages/redbot/cogs/warnings/warnings.py", line 249, in warn
    "points": reason_type["points"],
KeyError: 'points'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/red3/.local/lib/python3.5/site-packages/discord/ext/commands/bot.py", line 886, in invoke
    yield from ctx.command.invoke(ctx)
  File "/home/red3/.local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 514, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/home/red3/.local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 71, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'points'
```

Tried my luck in the discord but the suggestion was to open an issue, so here it is!



Discussion:
This can be reproduced if one did not set a registered reason. User probably thought the `reason` part work the same as mod action command, accepting any value

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
@@ -71,7 +71,9 @@ async def warnaction(self, ctx: commands.Context):
     @commands.guild_only()
     async def action_add(self, ctx: commands.Context, name: str, points: int):
         """Create an action to be taken at a specified point count
-        Duplicate action names are not allowed"""
+
+        Duplicate action names are not allowed
+        """
         guild = ctx.guild
 
         await ctx.send("Would you like to enter commands to be run? (y/n)")
@@ -219,8 +221,9 @@ async def actionlist(self, ctx: commands.Context):
     @checks.admin_or_permissions(ban_members=True)
     async def warn(self, ctx: commands.Context, user: discord.Member, reason: str):
         """Warn the user for the specified reason
-        Reason must be a registered reason, or custom if custom reasons are allowed"""
-        reason_type = {}
+
+        Reason must be a registered reason, or "custom" if custom reasons are allowed
+        """
         if reason.lower() == "custom":
             custom_allowed = await self.config.guild(ctx.guild).allow_custom_reasons()
             if not custom_allowed:
@@ -237,6 +240,7 @@ async def warn(self, ctx: commands.Context, user: discord.Member, reason: str):
             async with guild_settings.reasons() as registered_reasons:
                 if reason.lower() not in registered_reasons:
                     await ctx.send(_("That is not a registered reason!"))
+                    return
                 else:
                     reason_type = registered_reasons[reason.lower()]
 
@@ -261,9 +265,11 @@ async def warn(self, ctx: commands.Context, user: discord.Member, reason: str):
     @commands.guild_only()
     async def warnings(self, ctx: commands.Context, userid: int = None):
         """Show warnings for the specified user.
+
         If userid is None, show warnings for the person running the command
         Note that showing warnings for users other than yourself requires
-        appropriate permissions"""
+        appropriate permissions
+        """
         if userid is None:
             user = ctx.author
         else:


Test patch: