We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
BridgeOption not raising BadArgument when conversion fails 
### Summary

BridgeOption does not raise the correct error when conversion fails for a built-in type.

### Reproduction Steps

Create a bridge command with an Option parameter of type `int` (other built-ins also work here).
Then use the prefixed command with an invalid value.
This will raise ValueError (in the case of int), when BadArgument should be raised instead.

### Minimal Reproducible Code

```python
@bot.bridge_command()
async def test(ctx, value: Option(int, name='value')):
    await ctx.respond(str(value))
```


### Expected Results

BadArgument to be raised when using `-test a`

### Actual Results

ValueError is raised

```
Traceback (most recent call last):
  File "site-packages\discord\ext\commands\converter.py", line 1071, in _actual_conversion
    return await converter.convert(ctx, argument)
  File "site-packages\discord\ext\bridge\core.py", line 161, in convert
    converted = converter(argument)
ValueError: invalid literal for int() with base 10: 'a'
```

### Intents

default + message_content

### System Information

- Python v3.10.1-final
- py-cord v2.0.0-beta
    - py-cord pkg_resources: v2.0.0b7
- aiohttp v3.8.1
- system info: Windows 10 10.0.19042

### Checklist

- [X] I have searched the open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have removed my token from display, if visible.

### Additional Context

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `discord/ext/bridge/core.py`
Content:
```
1 """
2 The MIT License (MIT)
3 
4 Copyright (c) 2015-2021 Rapptz
5 Copyright (c) 2021-present Pycord Development
6 
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 and/or sell copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 DEALINGS IN THE SOFTWARE.
24 """
25 from typing import Union, Any
26 
27 import discord.commands.options
28 from discord.commands import Option, SlashCommand
29 from discord.enums import SlashCommandOptionType
30 
31 from ..commands import AutoShardedBot as ExtAutoShardedBot
32 from ..commands import BadArgument
33 from ..commands import Bot as ExtBot
34 from ..commands import (
35     Command,
36     Converter,
37     GuildChannelConverter,
38     RoleConverter,
39     UserConverter,
40 )
41 
42 __all__ = ("BridgeCommand", "bridge_command", "BridgeExtCommand", "BridgeSlashCommand")
43 
44 from ...utils import get
45 
46 
47 class BridgeSlashCommand(SlashCommand):
48     """
49     A subclass of :class:`.SlashCommand` that is used to implement bridge commands.
50     """
51     ...
52 
53 
54 class BridgeExtCommand(Command):
55     """
56     A subclass of :class:`.ext.commands.Command` that is used to implement bridge commands.
57     """
58     ...
59 
60 
61 class BridgeCommand:
62     def __init__(self, callback, **kwargs):
63         """
64         This is the base class for commands that are compatible with both traditional (prefix-based) commands and slash
65         commands.
66 
67         Parameters
68         ----------
69         callback: Callable[[BridgeContext, ...], Awaitable[Any]]
70             The callback to invoke when the command is executed. The first argument will be a :class:`BridgeContext`,
71             and any additional arguments will be passed to the callback. This callback must be a coroutine.
72         kwargs: Optional[Dict[str, Any]]
73             Keyword arguments that are directly passed to the respective command constructors.
74         """
75         self.callback = callback
76         self.kwargs = kwargs
77 
78     def get_ext_command(self):
79         """A method to get the ext.commands version of this command.
80 
81         Returns
82         -------
83         :class:`BridgeExtCommand`
84             The respective traditional (prefix-based) version of the command.
85         """
86         command = BridgeExtCommand(self.callback, **self.kwargs)
87         return command
88 
89     def get_application_command(self):
90         """A method to get the discord.commands version of this command.
91 
92         Returns
93         -------
94         :class:`BridgeSlashCommand`
95             The respective slash command version of the command.
96         """
97         command = BridgeSlashCommand(self.callback, **self.kwargs)
98         return command
99 
100     def add_to(self, bot: Union[ExtBot, ExtAutoShardedBot]) -> None:
101         """Adds the command to a bot.
102 
103         Parameters
104         ----------
105         bot: Union[:class:`ExtBot`, :class:`ExtAutoShardedBot`]
106             The bot to add the command to.
107         """
108         bot.add_command(self.get_ext_command())
109         bot.add_application_command(self.get_application_command())
110 
111 
112 def bridge_command(**kwargs):
113     """A decorator that is used to wrap a function as a command.
114 
115     Parameters
116     ----------
117     kwargs: Optional[Dict[str, Any]]
118         Keyword arguments that are directly passed to the respective command constructors.
119     """
120 
121     def decorator(callback):
122         return BridgeCommand(callback, **kwargs)
123 
124     return decorator
125 
126 
127 class MentionableConverter(Converter):
128     """A converter that can convert a mention to a user or a role."""
129 
130     async def convert(self, ctx, argument):
131         try:
132             return await RoleConverter().convert(ctx, argument)
133         except BadArgument:
134             return await UserConverter().convert(ctx, argument)
135 
136 
137 def attachment_callback(*args):  # pylint: disable=unused-argument
138     raise ValueError("Attachments are not supported for compatibility commands.")
139 
140 
141 class BridgeOption(Option, Converter):
142     async def convert(self, ctx, argument) -> Any:
143         if self.converter is not None:
144             converted = await self.converter.convert(ctx, argument)
145         else:
146             mapping = {
147                 SlashCommandOptionType.string: str,
148                 SlashCommandOptionType.integer: int,
149                 SlashCommandOptionType.boolean: bool,
150                 SlashCommandOptionType.user: UserConverter,
151                 SlashCommandOptionType.channel: GuildChannelConverter,
152                 SlashCommandOptionType.role: RoleConverter,
153                 SlashCommandOptionType.mentionable: MentionableConverter,
154                 SlashCommandOptionType.number: float,
155                 SlashCommandOptionType.attachment: attachment_callback,
156             }
157             converter = mapping[self.input_type]
158             if issubclass(converter, Converter):
159                 converted = await converter().convert(ctx, argument)
160             else:
161                 converted = converter(argument)
162         if self.choices:
163             choices_names = [choice.name for choice in self.choices]
164             if converted in choices_names:
165                 converted = get(self.choices, name=converted).value
166             else:
167                 choices = [choice.value for choice in self.choices]
168                 if converted not in choices:
169                     print(self.choices)
170                     raise ValueError(
171                         f"{argument} is not a valid choice. Valid choices: {list(set(choices_names + choices))}"
172                     )
173 
174         return converted
175 
176 
177 discord.commands.options.Option = BridgeOption
178
```
--- 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/discord/ext/bridge/core.py b/discord/ext/bridge/core.py
--- a/discord/ext/bridge/core.py
+++ b/discord/ext/bridge/core.py
@@ -41,6 +41,8 @@
 
 __all__ = ("BridgeCommand", "bridge_command", "BridgeExtCommand", "BridgeSlashCommand")
 
+from ..commands.converter import _convert_to_bool
+
 from ...utils import get
 
 
@@ -140,38 +142,40 @@
 
 class BridgeOption(Option, Converter):
     async def convert(self, ctx, argument) -> Any:
-        if self.converter is not None:
-            converted = await self.converter.convert(ctx, argument)
-        else:
-            mapping = {
-                SlashCommandOptionType.string: str,
-                SlashCommandOptionType.integer: int,
-                SlashCommandOptionType.boolean: bool,
-                SlashCommandOptionType.user: UserConverter,
-                SlashCommandOptionType.channel: GuildChannelConverter,
-                SlashCommandOptionType.role: RoleConverter,
-                SlashCommandOptionType.mentionable: MentionableConverter,
-                SlashCommandOptionType.number: float,
-                SlashCommandOptionType.attachment: attachment_callback,
-            }
-            converter = mapping[self.input_type]
-            if issubclass(converter, Converter):
-                converted = await converter().convert(ctx, argument)
-            else:
-                converted = converter(argument)
-        if self.choices:
-            choices_names = [choice.name for choice in self.choices]
-            if converted in choices_names:
-                converted = get(self.choices, name=converted).value
+        try:
+            if self.converter is not None:
+                converted = await self.converter.convert(ctx, argument)
             else:
-                choices = [choice.value for choice in self.choices]
-                if converted not in choices:
-                    print(self.choices)
-                    raise ValueError(
-                        f"{argument} is not a valid choice. Valid choices: {list(set(choices_names + choices))}"
-                    )
-
-        return converted
+                mapping = {
+                    SlashCommandOptionType.string: str,
+                    SlashCommandOptionType.integer: int,
+                    SlashCommandOptionType.boolean: lambda val: _convert_to_bool(str(val)),
+                    SlashCommandOptionType.user: UserConverter,
+                    SlashCommandOptionType.channel: GuildChannelConverter,
+                    SlashCommandOptionType.role: RoleConverter,
+                    SlashCommandOptionType.mentionable: MentionableConverter,
+                    SlashCommandOptionType.number: float,
+                    SlashCommandOptionType.attachment: attachment_callback,
+                }
+                converter = mapping[self.input_type]
+                if issubclass(converter, Converter):
+                    converted = await converter().convert(ctx, argument)
+                else:
+                    converted = converter(argument)
+            if self.choices:
+                choices_names = [choice.name for choice in self.choices]
+                if converted in choices_names:
+                    converted = get(self.choices, name=converted).value
+                else:
+                    choices = [choice.value for choice in self.choices]
+                    if converted not in choices:
+                        raise ValueError(
+                            f"{argument} is not a valid choice. Valid choices: {list(set(choices_names + choices))}"
+                        )
+
+            return converted
+        except ValueError as exc:
+            raise BadArgument() from exc
 
 
 discord.commands.options.Option = BridgeOption

{"golden_diff": "diff --git a/discord/ext/bridge/core.py b/discord/ext/bridge/core.py\n--- a/discord/ext/bridge/core.py\n+++ b/discord/ext/bridge/core.py\n@@ -41,6 +41,8 @@\n \n __all__ = (\"BridgeCommand\", \"bridge_command\", \"BridgeExtCommand\", \"BridgeSlashCommand\")\n \n+from ..commands.converter import _convert_to_bool\n+\n from ...utils import get\n \n \n@@ -140,38 +142,40 @@\n \n class BridgeOption(Option, Converter):\n     async def convert(self, ctx, argument) -> Any:\n-        if self.converter is not None:\n-            converted = await self.converter.convert(ctx, argument)\n-        else:\n-            mapping = {\n-                SlashCommandOptionType.string: str,\n-                SlashCommandOptionType.integer: int,\n-                SlashCommandOptionType.boolean: bool,\n-                SlashCommandOptionType.user: UserConverter,\n-                SlashCommandOptionType.channel: GuildChannelConverter,\n-                SlashCommandOptionType.role: RoleConverter,\n-                SlashCommandOptionType.mentionable: MentionableConverter,\n-                SlashCommandOptionType.number: float,\n-                SlashCommandOptionType.attachment: attachment_callback,\n-            }\n-            converter = mapping[self.input_type]\n-            if issubclass(converter, Converter):\n-                converted = await converter().convert(ctx, argument)\n-            else:\n-                converted = converter(argument)\n-        if self.choices:\n-            choices_names = [choice.name for choice in self.choices]\n-            if converted in choices_names:\n-                converted = get(self.choices, name=converted).value\n+        try:\n+            if self.converter is not None:\n+                converted = await self.converter.convert(ctx, argument)\n             else:\n-                choices = [choice.value for choice in self.choices]\n-                if converted not in choices:\n-                    print(self.choices)\n-                    raise ValueError(\n-                        f\"{argument} is not a valid choice. Valid choices: {list(set(choices_names + choices))}\"\n-                    )\n-\n-        return converted\n+                mapping = {\n+                    SlashCommandOptionType.string: str,\n+                    SlashCommandOptionType.integer: int,\n+                    SlashCommandOptionType.boolean: lambda val: _convert_to_bool(str(val)),\n+                    SlashCommandOptionType.user: UserConverter,\n+                    SlashCommandOptionType.channel: GuildChannelConverter,\n+                    SlashCommandOptionType.role: RoleConverter,\n+                    SlashCommandOptionType.mentionable: MentionableConverter,\n+                    SlashCommandOptionType.number: float,\n+                    SlashCommandOptionType.attachment: attachment_callback,\n+                }\n+                converter = mapping[self.input_type]\n+                if issubclass(converter, Converter):\n+                    converted = await converter().convert(ctx, argument)\n+                else:\n+                    converted = converter(argument)\n+            if self.choices:\n+                choices_names = [choice.name for choice in self.choices]\n+                if converted in choices_names:\n+                    converted = get(self.choices, name=converted).value\n+                else:\n+                    choices = [choice.value for choice in self.choices]\n+                    if converted not in choices:\n+                        raise ValueError(\n+                            f\"{argument} is not a valid choice. Valid choices: {list(set(choices_names + choices))}\"\n+                        )\n+\n+            return converted\n+        except ValueError as exc:\n+            raise BadArgument() from exc\n \n \n discord.commands.options.Option = BridgeOption\n", "issue": "BridgeOption not raising BadArgument when conversion fails \n### Summary\n\nBridgeOption does not raise the correct error when conversion fails for a built-in type.\n\n### Reproduction Steps\n\nCreate a bridge command with an Option parameter of type `int` (other built-ins also work here).\r\nThen use the prefixed command with an invalid value.\r\nThis will raise ValueError (in the case of int), when BadArgument should be raised instead.\n\n### Minimal Reproducible Code\n\n```python\n@bot.bridge_command()\r\nasync def test(ctx, value: Option(int, name='value')):\r\n    await ctx.respond(str(value))\n```\n\n\n### Expected Results\n\nBadArgument to be raised when using `-test a`\n\n### Actual Results\n\nValueError is raised\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"site-packages\\discord\\ext\\commands\\converter.py\", line 1071, in _actual_conversion\r\n    return await converter.convert(ctx, argument)\r\n  File \"site-packages\\discord\\ext\\bridge\\core.py\", line 161, in convert\r\n    converted = converter(argument)\r\nValueError: invalid literal for int() with base 10: 'a'\r\n```\n\n### Intents\n\ndefault + message_content\n\n### System Information\n\n- Python v3.10.1-final\r\n- py-cord v2.0.0-beta\r\n    - py-cord pkg_resources: v2.0.0b7\r\n- aiohttp v3.8.1\r\n- system info: Windows 10 10.0.19042\n\n### Checklist\n\n- [X] I have searched the open issues for duplicates.\n- [X] I have shown the entire traceback, if possible.\n- [X] I have removed my token from display, if visible.\n\n### Additional Context\n\n_No response_\n", "before_files": [{"content": "\"\"\"\nThe MIT License (MIT)\n\nCopyright (c) 2015-2021 Rapptz\nCopyright (c) 2021-present Pycord Development\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the \"Software\"),\nto deal in the Software without restriction, including without limitation\nthe rights to use, copy, modify, merge, publish, distribute, sublicense,\nand/or sell copies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n\"\"\"\nfrom typing import Union, Any\n\nimport discord.commands.options\nfrom discord.commands import Option, SlashCommand\nfrom discord.enums import SlashCommandOptionType\n\nfrom ..commands import AutoShardedBot as ExtAutoShardedBot\nfrom ..commands import BadArgument\nfrom ..commands import Bot as ExtBot\nfrom ..commands import (\n    Command,\n    Converter,\n    GuildChannelConverter,\n    RoleConverter,\n    UserConverter,\n)\n\n__all__ = (\"BridgeCommand\", \"bridge_command\", \"BridgeExtCommand\", \"BridgeSlashCommand\")\n\nfrom ...utils import get\n\n\nclass BridgeSlashCommand(SlashCommand):\n    \"\"\"\n    A subclass of :class:`.SlashCommand` that is used to implement bridge commands.\n    \"\"\"\n    ...\n\n\nclass BridgeExtCommand(Command):\n    \"\"\"\n    A subclass of :class:`.ext.commands.Command` that is used to implement bridge commands.\n    \"\"\"\n    ...\n\n\nclass BridgeCommand:\n    def __init__(self, callback, **kwargs):\n        \"\"\"\n        This is the base class for commands that are compatible with both traditional (prefix-based) commands and slash\n        commands.\n\n        Parameters\n        ----------\n        callback: Callable[[BridgeContext, ...], Awaitable[Any]]\n            The callback to invoke when the command is executed. The first argument will be a :class:`BridgeContext`,\n            and any additional arguments will be passed to the callback. This callback must be a coroutine.\n        kwargs: Optional[Dict[str, Any]]\n            Keyword arguments that are directly passed to the respective command constructors.\n        \"\"\"\n        self.callback = callback\n        self.kwargs = kwargs\n\n    def get_ext_command(self):\n        \"\"\"A method to get the ext.commands version of this command.\n\n        Returns\n        -------\n        :class:`BridgeExtCommand`\n            The respective traditional (prefix-based) version of the command.\n        \"\"\"\n        command = BridgeExtCommand(self.callback, **self.kwargs)\n        return command\n\n    def get_application_command(self):\n        \"\"\"A method to get the discord.commands version of this command.\n\n        Returns\n        -------\n        :class:`BridgeSlashCommand`\n            The respective slash command version of the command.\n        \"\"\"\n        command = BridgeSlashCommand(self.callback, **self.kwargs)\n        return command\n\n    def add_to(self, bot: Union[ExtBot, ExtAutoShardedBot]) -> None:\n        \"\"\"Adds the command to a bot.\n\n        Parameters\n        ----------\n        bot: Union[:class:`ExtBot`, :class:`ExtAutoShardedBot`]\n            The bot to add the command to.\n        \"\"\"\n        bot.add_command(self.get_ext_command())\n        bot.add_application_command(self.get_application_command())\n\n\ndef bridge_command(**kwargs):\n    \"\"\"A decorator that is used to wrap a function as a command.\n\n    Parameters\n    ----------\n    kwargs: Optional[Dict[str, Any]]\n        Keyword arguments that are directly passed to the respective command constructors.\n    \"\"\"\n\n    def decorator(callback):\n        return BridgeCommand(callback, **kwargs)\n\n    return decorator\n\n\nclass MentionableConverter(Converter):\n    \"\"\"A converter that can convert a mention to a user or a role.\"\"\"\n\n    async def convert(self, ctx, argument):\n        try:\n            return await RoleConverter().convert(ctx, argument)\n        except BadArgument:\n            return await UserConverter().convert(ctx, argument)\n\n\ndef attachment_callback(*args):  # pylint: disable=unused-argument\n    raise ValueError(\"Attachments are not supported for compatibility commands.\")\n\n\nclass BridgeOption(Option, Converter):\n    async def convert(self, ctx, argument) -> Any:\n        if self.converter is not None:\n            converted = await self.converter.convert(ctx, argument)\n        else:\n            mapping = {\n                SlashCommandOptionType.string: str,\n                SlashCommandOptionType.integer: int,\n                SlashCommandOptionType.boolean: bool,\n                SlashCommandOptionType.user: UserConverter,\n                SlashCommandOptionType.channel: GuildChannelConverter,\n                SlashCommandOptionType.role: RoleConverter,\n                SlashCommandOptionType.mentionable: MentionableConverter,\n                SlashCommandOptionType.number: float,\n                SlashCommandOptionType.attachment: attachment_callback,\n            }\n            converter = mapping[self.input_type]\n            if issubclass(converter, Converter):\n                converted = await converter().convert(ctx, argument)\n            else:\n                converted = converter(argument)\n        if self.choices:\n            choices_names = [choice.name for choice in self.choices]\n            if converted in choices_names:\n                converted = get(self.choices, name=converted).value\n            else:\n                choices = [choice.value for choice in self.choices]\n                if converted not in choices:\n                    print(self.choices)\n                    raise ValueError(\n                        f\"{argument} is not a valid choice. Valid choices: {list(set(choices_names + choices))}\"\n                    )\n\n        return converted\n\n\ndiscord.commands.options.Option = BridgeOption\n", "path": "discord/ext/bridge/core.py"}], "after_files": [{"content": "\"\"\"\nThe MIT License (MIT)\n\nCopyright (c) 2015-2021 Rapptz\nCopyright (c) 2021-present Pycord Development\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the \"Software\"),\nto deal in the Software without restriction, including without limitation\nthe rights to use, copy, modify, merge, publish, distribute, sublicense,\nand/or sell copies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n\"\"\"\nfrom typing import Union, Any\n\nimport discord.commands.options\nfrom discord.commands import Option, SlashCommand\nfrom discord.enums import SlashCommandOptionType\n\nfrom ..commands import AutoShardedBot as ExtAutoShardedBot\nfrom ..commands import BadArgument\nfrom ..commands import Bot as ExtBot\nfrom ..commands import (\n    Command,\n    Converter,\n    GuildChannelConverter,\n    RoleConverter,\n    UserConverter,\n)\n\n__all__ = (\"BridgeCommand\", \"bridge_command\", \"BridgeExtCommand\", \"BridgeSlashCommand\")\n\nfrom ..commands.converter import _convert_to_bool\n\nfrom ...utils import get\n\n\nclass BridgeSlashCommand(SlashCommand):\n    \"\"\"\n    A subclass of :class:`.SlashCommand` that is used to implement bridge commands.\n    \"\"\"\n    ...\n\n\nclass BridgeExtCommand(Command):\n    \"\"\"\n    A subclass of :class:`.ext.commands.Command` that is used to implement bridge commands.\n    \"\"\"\n    ...\n\n\nclass BridgeCommand:\n    def __init__(self, callback, **kwargs):\n        \"\"\"\n        This is the base class for commands that are compatible with both traditional (prefix-based) commands and slash\n        commands.\n\n        Parameters\n        ----------\n        callback: Callable[[BridgeContext, ...], Awaitable[Any]]\n            The callback to invoke when the command is executed. The first argument will be a :class:`BridgeContext`,\n            and any additional arguments will be passed to the callback. This callback must be a coroutine.\n        kwargs: Optional[Dict[str, Any]]\n            Keyword arguments that are directly passed to the respective command constructors.\n        \"\"\"\n        self.callback = callback\n        self.kwargs = kwargs\n\n    def get_ext_command(self):\n        \"\"\"A method to get the ext.commands version of this command.\n\n        Returns\n        -------\n        :class:`BridgeExtCommand`\n            The respective traditional (prefix-based) version of the command.\n        \"\"\"\n        command = BridgeExtCommand(self.callback, **self.kwargs)\n        return command\n\n    def get_application_command(self):\n        \"\"\"A method to get the discord.commands version of this command.\n\n        Returns\n        -------\n        :class:`BridgeSlashCommand`\n            The respective slash command version of the command.\n        \"\"\"\n        command = BridgeSlashCommand(self.callback, **self.kwargs)\n        return command\n\n    def add_to(self, bot: Union[ExtBot, ExtAutoShardedBot]) -> None:\n        \"\"\"Adds the command to a bot.\n\n        Parameters\n        ----------\n        bot: Union[:class:`ExtBot`, :class:`ExtAutoShardedBot`]\n            The bot to add the command to.\n        \"\"\"\n        bot.add_command(self.get_ext_command())\n        bot.add_application_command(self.get_application_command())\n\n\ndef bridge_command(**kwargs):\n    \"\"\"A decorator that is used to wrap a function as a command.\n\n    Parameters\n    ----------\n    kwargs: Optional[Dict[str, Any]]\n        Keyword arguments that are directly passed to the respective command constructors.\n    \"\"\"\n\n    def decorator(callback):\n        return BridgeCommand(callback, **kwargs)\n\n    return decorator\n\n\nclass MentionableConverter(Converter):\n    \"\"\"A converter that can convert a mention to a user or a role.\"\"\"\n\n    async def convert(self, ctx, argument):\n        try:\n            return await RoleConverter().convert(ctx, argument)\n        except BadArgument:\n            return await UserConverter().convert(ctx, argument)\n\n\ndef attachment_callback(*args):  # pylint: disable=unused-argument\n    raise ValueError(\"Attachments are not supported for compatibility commands.\")\n\n\nclass BridgeOption(Option, Converter):\n    async def convert(self, ctx, argument) -> Any:\n        try:\n            if self.converter is not None:\n                converted = await self.converter.convert(ctx, argument)\n            else:\n                mapping = {\n                    SlashCommandOptionType.string: str,\n                    SlashCommandOptionType.integer: int,\n                    SlashCommandOptionType.boolean: lambda val: _convert_to_bool(str(val)),\n                    SlashCommandOptionType.user: UserConverter,\n                    SlashCommandOptionType.channel: GuildChannelConverter,\n                    SlashCommandOptionType.role: RoleConverter,\n                    SlashCommandOptionType.mentionable: MentionableConverter,\n                    SlashCommandOptionType.number: float,\n                    SlashCommandOptionType.attachment: attachment_callback,\n                }\n                converter = mapping[self.input_type]\n                if issubclass(converter, Converter):\n                    converted = await converter().convert(ctx, argument)\n                else:\n                    converted = converter(argument)\n            if self.choices:\n                choices_names = [choice.name for choice in self.choices]\n                if converted in choices_names:\n                    converted = get(self.choices, name=converted).value\n                else:\n                    choices = [choice.value for choice in self.choices]\n                    if converted not in choices:\n                        raise ValueError(\n                            f\"{argument} is not a valid choice. Valid choices: {list(set(choices_names + choices))}\"\n                        )\n\n            return converted\n        except ValueError as exc:\n            raise BadArgument() from exc\n\n\ndiscord.commands.options.Option = BridgeOption\n", "path": "discord/ext/bridge/core.py"}]}