We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[V3 Parser] --dry-run flag not handled 
# Other bugs

#### What were you trying to do?

I was trying to run the bot with the `--dry-run` flag

#### What were you expecting to happen?

See the bot loading data, then stop before connecting to the gateway
```
  --dry-run             Makes Red quit with code 0 just before the login. This
                        is useful for testing the boot process.
```
#### What actually happened?

The bot connected to the gateway as usual, like if there weren't flags 

#### How can we reproduce this issue?

Just run any bot with the `--dry-run` and see if it change something

### Details

I searched for the flag in the source code to see if it was actually being used somewhere... No results.

*Nice issues templates btw*

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `redbot/__main__.py`
Content:
```
1 #!/usr/bin/env python
2 
3 # Discord Version check
4 
5 import sys
6 import discord
7 from redbot.core.bot import Red, ExitCodes
8 from redbot.core.cog_manager import CogManagerUI
9 from redbot.core.data_manager import load_basic_configuration, config_file
10 from redbot.core.json_io import JsonIO
11 from redbot.core.global_checks import init_global_checks
12 from redbot.core.events import init_events
13 from redbot.core.cli import interactive_config, confirm, parse_cli_flags, ask_sentry
14 from redbot.core.core_commands import Core
15 from redbot.core.dev_commands import Dev
16 from redbot.core import rpc, __version__
17 import asyncio
18 import logging.handlers
19 import logging
20 import os
21 
22 
23 #
24 #               Red - Discord Bot v3
25 #
26 #         Made by Twentysix, improved by many
27 #
28 
29 
30 def init_loggers(cli_flags):
31     # d.py stuff
32     dpy_logger = logging.getLogger("discord")
33     dpy_logger.setLevel(logging.WARNING)
34     console = logging.StreamHandler()
35     console.setLevel(logging.WARNING)
36     dpy_logger.addHandler(console)
37 
38     # Red stuff
39 
40     logger = logging.getLogger("red")
41 
42     red_format = logging.Formatter(
43         "%(asctime)s %(levelname)s %(module)s %(funcName)s %(lineno)d: " "%(message)s",
44         datefmt="[%d/%m/%Y %H:%M]",
45     )
46 
47     stdout_handler = logging.StreamHandler(sys.stdout)
48     stdout_handler.setFormatter(red_format)
49 
50     if cli_flags.debug:
51         os.environ["PYTHONASYNCIODEBUG"] = "1"
52         logger.setLevel(logging.DEBUG)
53     else:
54         logger.setLevel(logging.WARNING)
55 
56     from redbot.core.data_manager import core_data_path
57 
58     logfile_path = core_data_path() / "red.log"
59     fhandler = logging.handlers.RotatingFileHandler(
60         filename=str(logfile_path), encoding="utf-8", mode="a", maxBytes=10 ** 7, backupCount=5
61     )
62     fhandler.setFormatter(red_format)
63 
64     logger.addHandler(fhandler)
65     logger.addHandler(stdout_handler)
66 
67     # Sentry stuff
68     sentry_logger = logging.getLogger("red.sentry")
69     sentry_logger.setLevel(logging.WARNING)
70 
71     return logger, sentry_logger
72 
73 
74 async def _get_prefix_and_token(red, indict):
75     """
76     Again, please blame <@269933075037814786> for this.
77     :param indict:
78     :return:
79     """
80     indict["token"] = await red.db.token()
81     indict["prefix"] = await red.db.prefix()
82     indict["enable_sentry"] = await red.db.enable_sentry()
83 
84 
85 def list_instances():
86     if not config_file.exists():
87         print(
88             "No instances have been configured! Configure one "
89             "using `redbot-setup` before trying to run the bot!"
90         )
91         sys.exit(1)
92     else:
93         data = JsonIO(config_file)._load_json()
94         text = "Configured Instances:\n\n"
95         for instance_name in sorted(data.keys()):
96             text += "{}\n".format(instance_name)
97         print(text)
98         sys.exit(0)
99 
100 
101 def main():
102     description = "Red - Version {}".format(__version__)
103     cli_flags = parse_cli_flags(sys.argv[1:])
104     if cli_flags.list_instances:
105         list_instances()
106     elif cli_flags.version:
107         print(description)
108         sys.exit(0)
109     elif not cli_flags.instance_name:
110         print("Error: No instance name was provided!")
111         sys.exit(1)
112     load_basic_configuration(cli_flags.instance_name)
113     log, sentry_log = init_loggers(cli_flags)
114     red = Red(cli_flags, description=description, pm_help=None)
115     init_global_checks(red)
116     init_events(red, cli_flags)
117     red.add_cog(Core(red))
118     red.add_cog(CogManagerUI())
119     if cli_flags.dev:
120         red.add_cog(Dev())
121     loop = asyncio.get_event_loop()
122     tmp_data = {}
123     loop.run_until_complete(_get_prefix_and_token(red, tmp_data))
124     token = os.environ.get("RED_TOKEN", tmp_data["token"])
125     prefix = cli_flags.prefix or tmp_data["prefix"]
126     if token is None or not prefix:
127         if cli_flags.no_prompt is False:
128             new_token = interactive_config(red, token_set=bool(token), prefix_set=bool(prefix))
129             if new_token:
130                 token = new_token
131         else:
132             log.critical("Token and prefix must be set in order to login.")
133             sys.exit(1)
134     loop.run_until_complete(_get_prefix_and_token(red, tmp_data))
135     if tmp_data["enable_sentry"]:
136         red.enable_sentry()
137     cleanup_tasks = True
138     try:
139         loop.run_until_complete(red.start(token, bot=not cli_flags.not_bot))
140     except discord.LoginFailure:
141         cleanup_tasks = False  # No login happened, no need for this
142         log.critical(
143             "This token doesn't seem to be valid. If it belongs to "
144             "a user account, remember that the --not-bot flag "
145             "must be used. For self-bot functionalities instead, "
146             "--self-bot"
147         )
148         db_token = red.db.token()
149         if db_token and not cli_flags.no_prompt:
150             print("\nDo you want to reset the token? (y/n)")
151             if confirm("> "):
152                 loop.run_until_complete(red.db.token.set(""))
153                 print("Token has been reset.")
154     except KeyboardInterrupt:
155         log.info("Keyboard interrupt detected. Quitting...")
156         loop.run_until_complete(red.logout())
157         red._shutdown_mode = ExitCodes.SHUTDOWN
158     except Exception as e:
159         log.critical("Fatal exception", exc_info=e)
160         sentry_log.critical("Fatal Exception", exc_info=e)
161         loop.run_until_complete(red.logout())
162     finally:
163         red.rpc.close()
164         if cleanup_tasks:
165             pending = asyncio.Task.all_tasks(loop=red.loop)
166             gathered = asyncio.gather(*pending, loop=red.loop, return_exceptions=True)
167             gathered.cancel()
168 
169         sys.exit(red._shutdown_mode.value)
170 
171 
172 if __name__ == "__main__":
173     main()
174
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/redbot/__main__.py b/redbot/__main__.py
--- a/redbot/__main__.py
+++ b/redbot/__main__.py
@@ -132,6 +132,10 @@
             log.critical("Token and prefix must be set in order to login.")
             sys.exit(1)
     loop.run_until_complete(_get_prefix_and_token(red, tmp_data))
+
+    if cli_flags.dry_run:
+        loop.run_until_complete(red.http.close())
+        sys.exit(0)
     if tmp_data["enable_sentry"]:
         red.enable_sentry()
     cleanup_tasks = True

{"golden_diff": "diff --git a/redbot/__main__.py b/redbot/__main__.py\n--- a/redbot/__main__.py\n+++ b/redbot/__main__.py\n@@ -132,6 +132,10 @@\n             log.critical(\"Token and prefix must be set in order to login.\")\n             sys.exit(1)\n     loop.run_until_complete(_get_prefix_and_token(red, tmp_data))\n+\n+    if cli_flags.dry_run:\n+        loop.run_until_complete(red.http.close())\n+        sys.exit(0)\n     if tmp_data[\"enable_sentry\"]:\n         red.enable_sentry()\n     cleanup_tasks = True\n", "issue": "[V3 Parser] --dry-run flag not handled \n# Other bugs\r\n\r\n#### What were you trying to do?\r\n\r\nI was trying to run the bot with the `--dry-run` flag\r\n\r\n#### What were you expecting to happen?\r\n\r\nSee the bot loading data, then stop before connecting to the gateway\r\n```\r\n  --dry-run             Makes Red quit with code 0 just before the login. This\r\n                        is useful for testing the boot process.\r\n```\r\n#### What actually happened?\r\n\r\nThe bot connected to the gateway as usual, like if there weren't flags \r\n\r\n#### How can we reproduce this issue?\r\n\r\nJust run any bot with the `--dry-run` and see if it change something\r\n\r\n### Details\r\n\r\nI searched for the flag in the source code to see if it was actually being used somewhere... No results.\r\n\r\n*Nice issues templates btw*\n", "before_files": [{"content": "#!/usr/bin/env python\n\n# Discord Version check\n\nimport sys\nimport discord\nfrom redbot.core.bot import Red, ExitCodes\nfrom redbot.core.cog_manager import CogManagerUI\nfrom redbot.core.data_manager import load_basic_configuration, config_file\nfrom redbot.core.json_io import JsonIO\nfrom redbot.core.global_checks import init_global_checks\nfrom redbot.core.events import init_events\nfrom redbot.core.cli import interactive_config, confirm, parse_cli_flags, ask_sentry\nfrom redbot.core.core_commands import Core\nfrom redbot.core.dev_commands import Dev\nfrom redbot.core import rpc, __version__\nimport asyncio\nimport logging.handlers\nimport logging\nimport os\n\n\n#\n#               Red - Discord Bot v3\n#\n#         Made by Twentysix, improved by many\n#\n\n\ndef init_loggers(cli_flags):\n    # d.py stuff\n    dpy_logger = logging.getLogger(\"discord\")\n    dpy_logger.setLevel(logging.WARNING)\n    console = logging.StreamHandler()\n    console.setLevel(logging.WARNING)\n    dpy_logger.addHandler(console)\n\n    # Red stuff\n\n    logger = logging.getLogger(\"red\")\n\n    red_format = logging.Formatter(\n        \"%(asctime)s %(levelname)s %(module)s %(funcName)s %(lineno)d: \" \"%(message)s\",\n        datefmt=\"[%d/%m/%Y %H:%M]\",\n    )\n\n    stdout_handler = logging.StreamHandler(sys.stdout)\n    stdout_handler.setFormatter(red_format)\n\n    if cli_flags.debug:\n        os.environ[\"PYTHONASYNCIODEBUG\"] = \"1\"\n        logger.setLevel(logging.DEBUG)\n    else:\n        logger.setLevel(logging.WARNING)\n\n    from redbot.core.data_manager import core_data_path\n\n    logfile_path = core_data_path() / \"red.log\"\n    fhandler = logging.handlers.RotatingFileHandler(\n        filename=str(logfile_path), encoding=\"utf-8\", mode=\"a\", maxBytes=10 ** 7, backupCount=5\n    )\n    fhandler.setFormatter(red_format)\n\n    logger.addHandler(fhandler)\n    logger.addHandler(stdout_handler)\n\n    # Sentry stuff\n    sentry_logger = logging.getLogger(\"red.sentry\")\n    sentry_logger.setLevel(logging.WARNING)\n\n    return logger, sentry_logger\n\n\nasync def _get_prefix_and_token(red, indict):\n    \"\"\"\n    Again, please blame <@269933075037814786> for this.\n    :param indict:\n    :return:\n    \"\"\"\n    indict[\"token\"] = await red.db.token()\n    indict[\"prefix\"] = await red.db.prefix()\n    indict[\"enable_sentry\"] = await red.db.enable_sentry()\n\n\ndef list_instances():\n    if not config_file.exists():\n        print(\n            \"No instances have been configured! Configure one \"\n            \"using `redbot-setup` before trying to run the bot!\"\n        )\n        sys.exit(1)\n    else:\n        data = JsonIO(config_file)._load_json()\n        text = \"Configured Instances:\\n\\n\"\n        for instance_name in sorted(data.keys()):\n            text += \"{}\\n\".format(instance_name)\n        print(text)\n        sys.exit(0)\n\n\ndef main():\n    description = \"Red - Version {}\".format(__version__)\n    cli_flags = parse_cli_flags(sys.argv[1:])\n    if cli_flags.list_instances:\n        list_instances()\n    elif cli_flags.version:\n        print(description)\n        sys.exit(0)\n    elif not cli_flags.instance_name:\n        print(\"Error: No instance name was provided!\")\n        sys.exit(1)\n    load_basic_configuration(cli_flags.instance_name)\n    log, sentry_log = init_loggers(cli_flags)\n    red = Red(cli_flags, description=description, pm_help=None)\n    init_global_checks(red)\n    init_events(red, cli_flags)\n    red.add_cog(Core(red))\n    red.add_cog(CogManagerUI())\n    if cli_flags.dev:\n        red.add_cog(Dev())\n    loop = asyncio.get_event_loop()\n    tmp_data = {}\n    loop.run_until_complete(_get_prefix_and_token(red, tmp_data))\n    token = os.environ.get(\"RED_TOKEN\", tmp_data[\"token\"])\n    prefix = cli_flags.prefix or tmp_data[\"prefix\"]\n    if token is None or not prefix:\n        if cli_flags.no_prompt is False:\n            new_token = interactive_config(red, token_set=bool(token), prefix_set=bool(prefix))\n            if new_token:\n                token = new_token\n        else:\n            log.critical(\"Token and prefix must be set in order to login.\")\n            sys.exit(1)\n    loop.run_until_complete(_get_prefix_and_token(red, tmp_data))\n    if tmp_data[\"enable_sentry\"]:\n        red.enable_sentry()\n    cleanup_tasks = True\n    try:\n        loop.run_until_complete(red.start(token, bot=not cli_flags.not_bot))\n    except discord.LoginFailure:\n        cleanup_tasks = False  # No login happened, no need for this\n        log.critical(\n            \"This token doesn't seem to be valid. If it belongs to \"\n            \"a user account, remember that the --not-bot flag \"\n            \"must be used. For self-bot functionalities instead, \"\n            \"--self-bot\"\n        )\n        db_token = red.db.token()\n        if db_token and not cli_flags.no_prompt:\n            print(\"\\nDo you want to reset the token? (y/n)\")\n            if confirm(\"> \"):\n                loop.run_until_complete(red.db.token.set(\"\"))\n                print(\"Token has been reset.\")\n    except KeyboardInterrupt:\n        log.info(\"Keyboard interrupt detected. Quitting...\")\n        loop.run_until_complete(red.logout())\n        red._shutdown_mode = ExitCodes.SHUTDOWN\n    except Exception as e:\n        log.critical(\"Fatal exception\", exc_info=e)\n        sentry_log.critical(\"Fatal Exception\", exc_info=e)\n        loop.run_until_complete(red.logout())\n    finally:\n        red.rpc.close()\n        if cleanup_tasks:\n            pending = asyncio.Task.all_tasks(loop=red.loop)\n            gathered = asyncio.gather(*pending, loop=red.loop, return_exceptions=True)\n            gathered.cancel()\n\n        sys.exit(red._shutdown_mode.value)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "redbot/__main__.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\n# Discord Version check\n\nimport sys\nimport discord\nfrom redbot.core.bot import Red, ExitCodes\nfrom redbot.core.cog_manager import CogManagerUI\nfrom redbot.core.data_manager import load_basic_configuration, config_file\nfrom redbot.core.json_io import JsonIO\nfrom redbot.core.global_checks import init_global_checks\nfrom redbot.core.events import init_events\nfrom redbot.core.cli import interactive_config, confirm, parse_cli_flags, ask_sentry\nfrom redbot.core.core_commands import Core\nfrom redbot.core.dev_commands import Dev\nfrom redbot.core import rpc, __version__\nimport asyncio\nimport logging.handlers\nimport logging\nimport os\n\n\n#\n#               Red - Discord Bot v3\n#\n#         Made by Twentysix, improved by many\n#\n\n\ndef init_loggers(cli_flags):\n    # d.py stuff\n    dpy_logger = logging.getLogger(\"discord\")\n    dpy_logger.setLevel(logging.WARNING)\n    console = logging.StreamHandler()\n    console.setLevel(logging.WARNING)\n    dpy_logger.addHandler(console)\n\n    # Red stuff\n\n    logger = logging.getLogger(\"red\")\n\n    red_format = logging.Formatter(\n        \"%(asctime)s %(levelname)s %(module)s %(funcName)s %(lineno)d: \" \"%(message)s\",\n        datefmt=\"[%d/%m/%Y %H:%M]\",\n    )\n\n    stdout_handler = logging.StreamHandler(sys.stdout)\n    stdout_handler.setFormatter(red_format)\n\n    if cli_flags.debug:\n        os.environ[\"PYTHONASYNCIODEBUG\"] = \"1\"\n        logger.setLevel(logging.DEBUG)\n    else:\n        logger.setLevel(logging.WARNING)\n\n    from redbot.core.data_manager import core_data_path\n\n    logfile_path = core_data_path() / \"red.log\"\n    fhandler = logging.handlers.RotatingFileHandler(\n        filename=str(logfile_path), encoding=\"utf-8\", mode=\"a\", maxBytes=10 ** 7, backupCount=5\n    )\n    fhandler.setFormatter(red_format)\n\n    logger.addHandler(fhandler)\n    logger.addHandler(stdout_handler)\n\n    # Sentry stuff\n    sentry_logger = logging.getLogger(\"red.sentry\")\n    sentry_logger.setLevel(logging.WARNING)\n\n    return logger, sentry_logger\n\n\nasync def _get_prefix_and_token(red, indict):\n    \"\"\"\n    Again, please blame <@269933075037814786> for this.\n    :param indict:\n    :return:\n    \"\"\"\n    indict[\"token\"] = await red.db.token()\n    indict[\"prefix\"] = await red.db.prefix()\n    indict[\"enable_sentry\"] = await red.db.enable_sentry()\n\n\ndef list_instances():\n    if not config_file.exists():\n        print(\n            \"No instances have been configured! Configure one \"\n            \"using `redbot-setup` before trying to run the bot!\"\n        )\n        sys.exit(1)\n    else:\n        data = JsonIO(config_file)._load_json()\n        text = \"Configured Instances:\\n\\n\"\n        for instance_name in sorted(data.keys()):\n            text += \"{}\\n\".format(instance_name)\n        print(text)\n        sys.exit(0)\n\n\ndef main():\n    description = \"Red - Version {}\".format(__version__)\n    cli_flags = parse_cli_flags(sys.argv[1:])\n    if cli_flags.list_instances:\n        list_instances()\n    elif cli_flags.version:\n        print(description)\n        sys.exit(0)\n    elif not cli_flags.instance_name:\n        print(\"Error: No instance name was provided!\")\n        sys.exit(1)\n    load_basic_configuration(cli_flags.instance_name)\n    log, sentry_log = init_loggers(cli_flags)\n    red = Red(cli_flags, description=description, pm_help=None)\n    init_global_checks(red)\n    init_events(red, cli_flags)\n    red.add_cog(Core(red))\n    red.add_cog(CogManagerUI())\n    if cli_flags.dev:\n        red.add_cog(Dev())\n    loop = asyncio.get_event_loop()\n    tmp_data = {}\n    loop.run_until_complete(_get_prefix_and_token(red, tmp_data))\n    token = os.environ.get(\"RED_TOKEN\", tmp_data[\"token\"])\n    prefix = cli_flags.prefix or tmp_data[\"prefix\"]\n    if token is None or not prefix:\n        if cli_flags.no_prompt is False:\n            new_token = interactive_config(red, token_set=bool(token), prefix_set=bool(prefix))\n            if new_token:\n                token = new_token\n        else:\n            log.critical(\"Token and prefix must be set in order to login.\")\n            sys.exit(1)\n    loop.run_until_complete(_get_prefix_and_token(red, tmp_data))\n\n    if cli_flags.dry_run:\n        loop.run_until_complete(red.http.close())\n        sys.exit(0)\n    if tmp_data[\"enable_sentry\"]:\n        red.enable_sentry()\n    cleanup_tasks = True\n    try:\n        loop.run_until_complete(red.start(token, bot=not cli_flags.not_bot))\n    except discord.LoginFailure:\n        cleanup_tasks = False  # No login happened, no need for this\n        log.critical(\n            \"This token doesn't seem to be valid. If it belongs to \"\n            \"a user account, remember that the --not-bot flag \"\n            \"must be used. For self-bot functionalities instead, \"\n            \"--self-bot\"\n        )\n        db_token = red.db.token()\n        if db_token and not cli_flags.no_prompt:\n            print(\"\\nDo you want to reset the token? (y/n)\")\n            if confirm(\"> \"):\n                loop.run_until_complete(red.db.token.set(\"\"))\n                print(\"Token has been reset.\")\n    except KeyboardInterrupt:\n        log.info(\"Keyboard interrupt detected. Quitting...\")\n        loop.run_until_complete(red.logout())\n        red._shutdown_mode = ExitCodes.SHUTDOWN\n    except Exception as e:\n        log.critical(\"Fatal exception\", exc_info=e)\n        sentry_log.critical(\"Fatal Exception\", exc_info=e)\n        loop.run_until_complete(red.logout())\n    finally:\n        red.rpc.close()\n        if cleanup_tasks:\n            pending = asyncio.Task.all_tasks(loop=red.loop)\n            gathered = asyncio.gather(*pending, loop=red.loop, return_exceptions=True)\n            gathered.cancel()\n\n        sys.exit(red._shutdown_mode.value)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "redbot/__main__.py"}]}