|
7 | 7 | from . import model |
8 | 8 | from . import error |
9 | 9 | from .utils import manage_commands |
| 10 | +from enum import IntEnum |
10 | 11 |
|
11 | 12 |
|
12 | 13 | class SlashCommand: |
@@ -427,9 +428,10 @@ async def _pick(ctx, choice1, choice2): # Command with 1 or more args. |
427 | 428 |
|
428 | 429 | .. code-block:: python |
429 | 430 |
|
430 | | - {"option_role": "role", # For key put name of the option and for value put type of the option. |
431 | | - "option_user": 6, # Also can use number for type |
432 | | - "option_channel": "CHANNEL"} # and all upper case. |
| 431 | + {"option_role": "role", # For key put name of the option and for value put type of the option. |
| 432 | + "option_user": SlashCommandOptionType.USER, # Also can use an enumeration member for the type |
| 433 | + "option_user_two": 6, # or number |
| 434 | + "option_channel": "CHANNEL"} # or upper case string. |
433 | 435 |
|
434 | 436 | :param name: Name of the slash command. Default name of the coroutine. |
435 | 437 | :type name: str |
@@ -565,15 +567,15 @@ async def process_options(self, guild: discord.Guild, options: list, auto_conver |
565 | 567 | types = { |
566 | 568 | "user": 0, |
567 | 569 | "USER": 0, |
568 | | - 6: 0, |
| 570 | + SlashCommandOptionType.USER: 0, |
569 | 571 | "6": 0, |
570 | 572 | "channel": 1, |
571 | 573 | "CHANNEL": 1, |
572 | | - 7: 1, |
| 574 | + SlashCommandOptionType.CHANNEL: 1, |
573 | 575 | "7": 1, |
574 | 576 | "role": 2, |
575 | 577 | "ROLE": 2, |
576 | | - 8: 2, |
| 578 | + SlashCommandOptionType.ROLE: 2, |
577 | 579 | "8": 2 |
578 | 580 | } |
579 | 581 |
|
@@ -731,3 +733,17 @@ async def on_slash_command_error(ctx, ex): |
731 | 733 | return |
732 | 734 | # Prints exception if not overrided or has no listener for error. |
733 | 735 | self.logger.exception(f"An exception has occurred while executing command `{ctx.name}`:") |
| 736 | + |
| 737 | + |
| 738 | +class SlashCommandOptionType(IntEnum): |
| 739 | + """ |
| 740 | + Equivalent of `ApplicationCommandOptionType <https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype>`_ in the Discord API. |
| 741 | + """ |
| 742 | + SUB_COMMAND = 1 |
| 743 | + SUB_COMMAND_GROUP = 2 |
| 744 | + STRING = 3 |
| 745 | + INTEGER = 4 |
| 746 | + BOOLEAN = 5 |
| 747 | + USER = 6 |
| 748 | + CHANNEL = 7 |
| 749 | + ROLE = 8 |
0 commit comments