internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: Cog-Creators/Red-DiscordBot

Issue:
Config docs issue
http://i.imgur.com/FdowiQS.png

In that screenshot, the docstring for `register_guild` was copied and pasted, without changes, to `register_member`, `register_role`, and `register_user`. That should be changed (by making the appropriate edits to the docstrings for those three functions in `core/config.py`).


Discussion:
Does this still need to be addressed? Is @Tobotimus going to make a PR?
At this point making a pr is fine. I will judge it on a first come, first serve basis.
@endotnick No, the "help wanted" tag is to encourage new people to contribute, and I'm not really new, so you're welcome to make a PR

Resolving patch:
diff --git a/redbot/core/config.py b/redbot/core/config.py
--- a/redbot/core/config.py
+++ b/redbot/core/config.py
@@ -573,26 +573,26 @@ def register_guild(self, **kwargs):
 
     def register_channel(self, **kwargs):
         """
-        Registers default values on a per-guild level. See :py:meth:`register_global` for more details.
+        Registers default values on a per-channel level. See :py:meth:`register_global` for more details.
         """
         # We may need to add a voice channel category later
         self._register_default(self.CHANNEL, **kwargs)
 
     def register_role(self, **kwargs):
         """
-        Registers default values on a per-guild level. See :py:meth:`register_global` for more details.
+        Registers default values on a per-role level. See :py:meth:`register_global` for more details.
         """
         self._register_default(self.ROLE, **kwargs)
 
     def register_user(self, **kwargs):
         """
-        Registers default values on a per-guild level. See :py:meth:`register_global` for more details.
+        Registers default values on a per-user level (i.e. server-independent). See :py:meth:`register_global` for more details.
         """
         self._register_default(self.USER, **kwargs)
 
     def register_member(self, **kwargs):
         """
-        Registers default values on a per-guild level. See :py:meth:`register_global` for more details.
+        Registers default values on a per-member level (i.e. server-dependent). See :py:meth:`register_global` for more details.
         """
         self._register_default(self.MEMBER, **kwargs)
 


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Modlog] Duplicate cases created on bans
Duplicate cases are being created when using the `ban` command. This is likely due to the `on_member_ban` event in `Mod`


Discussion:
I think that this can be fixed by adding a condition that checks if a ban is issued by the current bot account.
As example: grab the newest ban event, check if the user is the current bot and then assign logic based on that.

Resolving patch:
diff --git a/redbot/cogs/mod/mod.py b/redbot/cogs/mod/mod.py
--- a/redbot/cogs/mod/mod.py
+++ b/redbot/cogs/mod/mod.py
@@ -1167,8 +1167,9 @@ async def on_member_ban(self, guild: discord.Guild, member: discord.Member):
                 mod = audit_case.user
                 reason = audit_case.reason
                 for case in sorted(modlog_cases, key=lambda x: x.case_number, reverse=True):
-                    if case.moderator == mod and case.user == member\
+                    if mod == guild.me and case.user == member\
                             and case.action_type in ["ban", "hackban"]:
+                        log.info("Case already exists for ban of {}".format(member.name))
                         break
                 else:  # no ban, softban, or hackban case with the mod and user combo
                     try:
@@ -1231,8 +1232,9 @@ async def on_member_unban(self, guild: discord.Guild, user: discord.User):
 
                 cases = await modlog.get_all_cases(guild, self.bot)
                 for case in sorted(cases, key=lambda x: x.case_number, reverse=True):
-                    if case.moderator == mod and case.user == user\
-                            and case.action_type == "unban": 
+                    if mod == guild.me and case.user == user\
+                            and case.action_type == "unban":
+                        log.info("Case already exists for unban of {}".format(user.name))
                         break
                 else:
                     try:


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[Streams] Twitch: User can't remove stream alert on stream username change



Discussion:

Resolving patch:
diff --git a/cogs/streams.py b/cogs/streams.py
--- a/cogs/streams.py
+++ b/cogs/streams.py
@@ -524,9 +524,13 @@ def picarto_embed(self, data):
     def enable_or_disable_if_active(self, streams, stream, channel, _id=None):
         """Returns True if enabled or False if disabled"""
         for i, s in enumerate(streams):
-            if s["NAME"] != stream:
-                continue
-
+            stream_id = s.get("ID")
+            if stream_id and _id:     # ID is available, matching by ID is
+                if stream_id != _id:  # preferable
+                    continue
+            else:  # ID unavailable, matching by name
+                if s["NAME"] != stream:
+                    continue
             if channel.id in s["CHANNELS"]:
                 streams[i]["CHANNELS"].remove(channel.id)
                 if not s["CHANNELS"]:


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Beta 3 Streams] 'Task' Object has no attribute 'append' when
### Type:

Bug

### Brief description of the problem

`!streamalert twitch channel <channel_name>` gives error `'Task' object has no attribute 'append'` 

### Expected behavior

Add a stream to the list of channels to be alerted for

### Actual behavior

Error...

### Steps to reproduce

1. Execute command `!streamalert twitch channel` with any (valid) stream name

### Observations

Line 44 of `cogs/streams/main.py`'s assignment to `self.streams` from `self.bot.loop.create_task` returns a `Task` object instead of a `list` or similar. (No other object assignments found).



Discussion:

Resolving patch:
diff --git a/redbot/cogs/streams/main.py b/redbot/cogs/streams/main.py
--- a/redbot/cogs/streams/main.py
+++ b/redbot/cogs/streams/main.py
@@ -41,8 +41,12 @@ def __init__(self, bot: Red):
 
         self.bot = bot
 
-        self.streams = self.bot.loop.create_task(self.load_streams())
-        self.communities = self.bot.loop.create_task(self.load_communities())
+        self.bot.loop.create_task(self._initialize_lists())
+
+    async def _initialize_lists(self):
+        self.streams = await self.load_streams()
+        self.communities = await self.load_communities()
+
         self.task = self.bot.loop.create_task(self._stream_alerts())
 
     @commands.command()


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3] [p]mock doesn't work with aliases
Please be sure to read through other issues as well to make sure what you are suggesting/reporting has not already
been suggested/reported

### Type:

- [ ] Suggestion
- [x] Bug

### Brief description of the problem
Attempting to run an alias as another user with `[p]mock` does nothing

### Expected behavior
It should run the command the alias is for

### Actual behavior
It does nothing
### Steps to reproduce

1. Create an alias (for example, `[p]alias add c contact`
2. Try to use mock with it (`[p]mock <user> c`)
3. Nothing happens



Discussion:

Resolving patch:
diff --git a/redbot/core/dev_commands.py b/redbot/core/dev_commands.py
--- a/redbot/core/dev_commands.py
+++ b/redbot/core/dev_commands.py
@@ -4,6 +4,7 @@
 import textwrap
 import traceback
 from contextlib import redirect_stdout
+from copy import copy
 
 import discord
 from discord.ext import commands
@@ -286,17 +287,11 @@ async def mock(self, ctx, user: discord.Member, *, command):
 
         The prefix must not be entered.
         """
-        # Since we have stateful objects now this might be pretty bad
-        # Sorry Danny
-        old_author = ctx.author
-        old_content = ctx.message.content
-        ctx.message.author = user
-        ctx.message.content = ctx.prefix + command
+        msg = copy(ctx.message)
+        msg.author = user
+        msg.content = ctx.prefix + command
 
-        await ctx.bot.process_commands(ctx.message)
-
-        ctx.message.author = old_author
-        ctx.message.content = old_content
+        ctx.bot.dispatch('message', msg)
 
     @commands.command(name="mockmsg")
     @checks.is_owner()


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3] Error in command repl
### Type:

- [ ] Suggestion
- [x] Bug

### Brief description of the problem

So I first tried to use the core repl function on V3 for the first time. I set a very basic value and got an error

### Steps to reproduce

1. `=repl`
2. `level = 1`

![screen shot 2017-12-10 at 19 42 22](https://user-images.githubusercontent.com/23153234/33808207-a5778400-dde2-11e7-99a7-861432d50eda.png)

Full error:

```Py
Exception in command 'repl'
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/redbot/core/dev_commands.py", line 273, in repl
    msg = self.sanitize_output(ctx, msg)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/redbot/core/dev_commands.py", line 64, in sanitize_output
    result = input_.replace(token, r)
AttributeError: 'NoneType' object has no attribute 'replace'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 886, in invoke
    yield from ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 489, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/usr/local/lib/python3.6/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: AttributeError: 'NoneType' object has no attribute 'replace'
```


Discussion:

Resolving patch:
diff --git a/redbot/core/dev_commands.py b/redbot/core/dev_commands.py
--- a/redbot/core/dev_commands.py
+++ b/redbot/core/dev_commands.py
@@ -253,7 +253,7 @@ async def repl(self, ctx):
 
             stdout = io.StringIO()
 
-            msg = None
+            msg = ""
 
             try:
                 with redirect_stdout(stdout):


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
TypeError: Only messages, members or roles may be passed
https://sentry.io/will-tekulve/bot-development/issues/419244737/

```
TypeError: Only messages, members or roles may be passed
  File "redbot/core/utils/mod.py", line 132, in is_mod_or_superior
    raise TypeError('Only messages, members or roles may be passed')

Exception in on_message
```


Discussion:
This should be a fairly easy fix

Resolving patch:
diff --git a/redbot/core/utils/mod.py b/redbot/core/utils/mod.py
--- a/redbot/core/utils/mod.py
+++ b/redbot/core/utils/mod.py
@@ -124,7 +124,7 @@ async def is_mod_or_superior(
     user = None
     if isinstance(obj, discord.Message):
         user = obj.author
-    elif isinstance(obj, discord.Member):
+    elif isinstance(obj, discord.Member) or isinstance(obj, discord.User):
         user = obj
     elif isinstance(obj, discord.Role):
         pass
@@ -214,7 +214,7 @@ async def is_admin_or_superior(
     user = None
     if isinstance(obj, discord.Message):
         user = obj.author
-    elif isinstance(obj, discord.Member):
+    elif isinstance(obj, discord.Member) or isinstance(obj, discord.User):
         user = obj
     elif isinstance(obj, discord.Role):
         pass


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
TypeError: object Value can't be used in 'await' expression
https://sentry.io/will-tekulve/bot-development/issues/419249984/

```
TypeError: object Value can't be used in 'await' expression
  File "discord/client.py", line 223, in _run_event
    yield from coro(*args, **kwargs)
  File "filter/filter.py", line 309, in on_member_join
    name_to_use = await self.settings.guild(guild).filter_default_name

Exception in on_member_join
```
TypeError: object Value can't be used in 'await' expression
https://sentry.io/will-tekulve/bot-development/issues/419249984/

```
TypeError: object Value can't be used in 'await' expression
  File "discord/client.py", line 223, in _run_event
    yield from coro(*args, **kwargs)
  File "filter/filter.py", line 309, in on_member_join
    name_to_use = await self.settings.guild(guild).filter_default_name

Exception in on_member_join
```


Discussion:

Resolving patch:
diff --git a/redbot/cogs/filter/filter.py b/redbot/cogs/filter/filter.py
--- a/redbot/cogs/filter/filter.py
+++ b/redbot/cogs/filter/filter.py
@@ -306,7 +306,7 @@ async def on_member_join(self, member: discord.Member):
             return
         word_list = await self.settings.guild(guild).filter()
         filter_names = await self.settings.guild(guild).filter_names()
-        name_to_use = await self.settings.guild(guild).filter_default_name
+        name_to_use = await self.settings.guild(guild).filter_default_name()
 
         if not filter_names:
             return


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
AttributeError: 'MissingRequiredArgument' object has no attribute 'original'
https://sentry.io/will-tekulve/bot-development/issues/418646879/

```
AttributeError: 'MissingRequiredArgument' object has no attribute 'original'
  File "redbot/core/events.py", line 187, in on_command_error
    exc_info=error.original)

Exception in on_on_command_error
```


Discussion:

Resolving patch:
diff --git a/redbot/core/events.py b/redbot/core/events.py
--- a/redbot/core/events.py
+++ b/redbot/core/events.py
@@ -135,7 +135,7 @@ async def on_ready():
 
     @bot.event
     async def on_error(event_method, *args, **kwargs):
-        sentry_log.exception("Exception in on_{}".format(event_method))
+        sentry_log.exception("Exception in {}".format(event_method))
 
     @bot.event
     async def on_command_error(ctx, error):
@@ -160,6 +160,10 @@ async def on_command_error(ctx, error):
             log.exception("Exception in command '{}'"
                           "".format(ctx.command.qualified_name),
                           exc_info=error.original)
+            sentry_log.exception("Exception in command '{}'"
+                                 "".format(ctx.command.qualified_name),
+                                 exc_info=error.original)
+
             message = ("Error in command '{}'. Check your console or "
                        "logs for details."
                        "".format(ctx.command.qualified_name))
@@ -181,10 +185,13 @@ async def on_command_error(ctx, error):
                            "".format(error.retry_after))
         else:
             log.exception(type(error).__name__, exc_info=error)
+            try:
+                sentry_error = error.original
+            except AttributeError:
+                sentry_error = error
 
-        sentry_log.exception("Exception in command '{}'"
-                             "".format(ctx.command.qualified_name),
-                             exc_info=error.original)
+            sentry_log.exception("Unhandled command error.",
+                                 exc_info=sentry_error)
 
     @bot.event
     async def on_message(message):


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3] Offers cli flags after invalid input
### Type:

- [ ] Suggestion
- [X] Bug

### Brief description of the problem
Launcher still asks for cli flags after fail

### Expected behavior
When selecting an instance index, if the input is invalid, don't ask for cli flags

### Actual behavior
Using the redbot-launcher, when selecting choice 1 or 2 to start an instance, if an invalid value is given, the launcher still asks for cli flags

### Steps to reproduce

1. redbot-launcher
2. 2
3. type random stuff on input for which instance you'd like to start

![image](https://user-images.githubusercontent.com/23440577/33813731-a3c24980-de8a-11e7-9043-bf3a6802bc60.png)



Discussion:

Resolving patch:
diff --git a/redbot/launcher.py b/redbot/launcher.py
--- a/redbot/launcher.py
+++ b/redbot/launcher.py
@@ -202,24 +202,24 @@ def instance_menu():
         return None
     counter = 0
     print("Red instance menu\n")
-   
+
     name_num_map = {}
     for name in list(instances.keys()):
         print("{}. {}\n".format(counter+1, name))
         name_num_map[str(counter+1)] = name
         counter += 1
-    selection = user_choice()
-    try:
-        selection = int(selection)
-    except ValueError:
-        print("Invalid input! Try again.")
-        return None
-    else:
-        if selection not in list(range(1, counter+1)):
-            print("Invalid selection! Please try again")
-            return None
+
+    while True:
+        selection = user_choice()
+        try:
+            selection = int(selection)
+        except ValueError:
+            print("Invalid input! Please enter a number corresponding to an instance.")
         else:
-            return name_num_map[str(selection)]
+            if selection not in list(range(1, counter+1)):
+                print("Invalid selection! Please try again")
+            else:
+                return name_num_map[str(selection)]
 
 
 def clear_screen():


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Cleanup] Handle getting coroutine prefixes for [p]cleanup bot
### Type

- Bug

### Description
Coroutine prefixes aren't implemented for `cleanup bot`. This is kind of important since Red's default prefix is a coroutine.

This is pretty easy; we can just use `await bot.get_prefix(ctx.message)`, since this actually just returns a list of server prefixes.

[Relevant Sentry issue](https://sentry.io/will-tekulve/bot-development/issues/420947439/)

```
TypeError: argument of type 'coroutine' is not iterable
  File "discord/ext/commands/core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "cleanup/cleanup.py", line 234, in cleanup_bot
    if '' in prefixes:

Exception in command 'cleanup bot'
```


Discussion:

Resolving patch:
diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py
--- a/redbot/cogs/cleanup/cleanup.py
+++ b/redbot/cogs/cleanup/cleanup.py
@@ -221,14 +221,9 @@ async def cleanup_bot(self, ctx: commands.Context, number: int):
         author = ctx.message.author
         is_bot = self.bot.user.bot
 
-        prefixes = self.bot.command_prefix
+        prefixes = await self.bot.get_prefix(ctx.message) # This returns all server prefixes
         if isinstance(prefixes, str):
             prefixes = [prefixes]
-        elif callable(prefixes):
-            if asyncio.iscoroutine(prefixes):
-                await ctx.send(_('Coroutine prefixes not yet implemented.'))
-                return
-            prefixes = prefixes(self.bot, ctx.message)
 
         # In case some idiot sets a null prefix
         if '' in prefixes:
@@ -241,7 +236,8 @@ def check(m):
                 return True
             p = discord.utils.find(m.content.startswith, prefixes)
             if p and len(p) > 0:
-                return m.content[len(p):].startswith(tuple(self.bot.commands))
+                cmd_name = m.content[len(p):].split(' ')[0]
+                return bool(self.bot.get_command(cmd_name))
             return False
 
         to_delete = [ctx.message]


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Context] Handle DMs properly during send_interactive
(*forwarded from @palmtree5*)

### Type:

- Bug

### Brief description of the problem
When a user in DM types `more` during a case of `ctx.send_interactive` (for example, a long response to `[p]debug`), an error occurs.

### Expected behavior
When a user types `more`, the bot's message *"type `more` to continue"* should be deleted.

### Actual behavior
```py
Exception in command 'debug'
Traceback (most recent call last):
  File "/home/palm/redv3/lib/python3.5/site-packages/discord/ext/commands/core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/home/palm/redv3/lib/python3.5/site-packages/redbot/core/dev_commands.py", line 124, in debug
    await ctx.send_interactive(self.get_pages(result), box_lang="py")
  File "/home/palm/redv3/lib/python3.5/site-packages/redbot/core/context.py", line 120, in send_interactive
    await self.channel.delete_messages((query, resp))
AttributeError: 'DMChannel' object has no attribute 'delete_messages'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/palm/redv3/lib/python3.5/site-packages/discord/ext/commands/bot.py", line 886, in invoke
    yield from ctx.command.invoke(ctx)
  File "/home/palm/redv3/lib/python3.5/site-packages/discord/ext/commands/core.py", line 489, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/home/palm/redv3/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: AttributeError: 'DMChannel' object has no attribute 'delete_messages'
```

### Steps to reproduce

1. Open a DM with the bot
2. Do `[p]debug dir(bot)`
3. Type `more` when queried



Discussion:

Resolving patch:
diff --git a/redbot/core/context.py b/redbot/core/context.py
--- a/redbot/core/context.py
+++ b/redbot/core/context.py
@@ -118,8 +118,9 @@ async def send_interactive(self,
                 else:
                     try:
                         await self.channel.delete_messages((query, resp))
-                    except discord.HTTPException:
+                    except (discord.HTTPException, AttributeError):
                         # In case the bot can't delete other users' messages,
                         # or is not a bot account
+                        # or chanel is a DM
                         await query.delete()
         return ret


Test patch:
Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Help Formatter] Help command's error handler has incorrect params
### Type

- Bug

### Description
The help formatter's error handler has incorrect parameters; it's not a method but has `self` as its first arg, and `ctx` and `error` args are around the wrong way. It should look like this:
```py
@help.error
async def help_error(ctx, error):
```

[Relevant sentry issue](https://sentry.io/will-tekulve/bot-development/issues/420992464/)


Discussion:

Resolving patch:
diff --git a/redbot/core/help_formatter.py b/redbot/core/help_formatter.py
--- a/redbot/core/help_formatter.py
+++ b/redbot/core/help_formatter.py
@@ -337,6 +337,7 @@ def repl(obj):
 
 
 @help.error
-async def help_error(self, error, ctx):
-    await self.destination.send('{0.__name__}: {1}'.format(type(error), error))
+async def help_error(ctx, error):
+    destination = ctx.author if ctx.bot.pm_help else ctx
+    await destination.send('{0.__name__}: {1}'.format(type(error), error))
     traceback.print_tb(error.original.__traceback__, file=sys.stderr)


Test patch: