|
40 | 40 | SlashCommandOptionType,
|
41 | 41 | )
|
42 | 42 |
|
43 |
| -from ...utils import MISSING, find, get |
| 43 | +from ...utils import MISSING, find, get, warn_deprecated |
44 | 44 | from ..commands import BadArgument
|
45 | 45 | from ..commands import Bot as ExtBot
|
46 | 46 | from ..commands import (
|
|
63 | 63 | "BridgeCommandGroup",
|
64 | 64 | "bridge_command",
|
65 | 65 | "bridge_group",
|
| 66 | + "bridge_option", |
66 | 67 | "BridgeExtCommand",
|
67 | 68 | "BridgeSlashCommand",
|
68 | 69 | "BridgeExtGroup",
|
@@ -627,3 +628,38 @@ async def convert(self, ctx, argument: str) -> Any:
|
627 | 628 | return converted
|
628 | 629 | except ValueError as exc:
|
629 | 630 | raise BadArgument() from exc
|
| 631 | + |
| 632 | + |
| 633 | +def bridge_option(name, input_type=None, **kwargs): |
| 634 | + """A decorator that can be used instead of typehinting :class:`.BridgeOption`. |
| 635 | +
|
| 636 | + .. versionadded:: 2.6 |
| 637 | +
|
| 638 | + Attributes |
| 639 | + ---------- |
| 640 | + parameter_name: :class:`str` |
| 641 | + The name of the target parameter this option is mapped to. |
| 642 | + This allows you to have a separate UI ``name`` and parameter name. |
| 643 | + """ |
| 644 | + |
| 645 | + def decorator(func): |
| 646 | + resolved_name = kwargs.pop("parameter_name", None) or name |
| 647 | + itype = ( |
| 648 | + kwargs.pop("type", None) |
| 649 | + or input_type |
| 650 | + or func.__annotations__.get(resolved_name, str) |
| 651 | + ) |
| 652 | + func.__annotations__[resolved_name] = BridgeOption(itype, name=name, **kwargs) |
| 653 | + return func |
| 654 | + |
| 655 | + return decorator |
| 656 | + |
| 657 | + |
| 658 | +discord.commands.options.Option = BridgeOption |
| 659 | +discord.Option = BridgeOption |
| 660 | +warn_deprecated( |
| 661 | + "Option", |
| 662 | + "BridgeOption", |
| 663 | + "2.5", |
| 664 | + reference="https://github.com/Pycord-Development/pycord/pull/2417", |
| 665 | +) |
0 commit comments