Repository: interactions-py/interactions.py

Issue:
Allow passing of types to discord_slash.utils.manage_commands.create_option
It would be nice to be able to pass a type, such as `str` or `discord.Role` to the `option_type` argument of the function `discord_slash.utils.manage_commands.create_option`
There may be other functions within that module which this could apply to, I haven't checked in depth. All it would need to do is map the type to an integer. For example: `str` would be `3`


Discussion:
This will be implemented in the next release.
Correct me if I'm wrong, but as far as I know getting options from the type hints of a function is planned.
They are talking about `discord_slash.utils.manage_commands.create_option` which currently doesn't accept `str, int, discord.[...] etc` as the `option_type` argument on the dev branch.
I haven't seen anything planned *specifically* about this
`model.SlashCommandOptionType.from_type(str)` -> would return string type which can be set in `create_option`
Building on this, I wish `model.SlashCommandOptionType` received a concatenation to `OptionType`. Pretty redundant to repeat something already known in the model script when it's an enum type.
I don't know if @eunwoo1104 wants to change that. Alternatively, you could just do `import discord_slash.model.SlashCommandOptionType as OptionType`.
Would integrating `SlashCommandOptionType` into `create_option` be a possible idea?
so that you don't have to do `create_option(option_type=SlashCommandOptionType.from_type(type), [...])`
> This will be implemented in the next release.

This is not planned feature.

> Would integrating `SlashCommandOptionType` into `create_option` be a possible idea?
> so that you don't have to do `create_option(option_type=SlashCommandOptionType.from_type(type), [...])`

This seems to be the good idea. I'll implement this when I get some times.

Resolving patch:
diff --git a/discord_slash/error.py b/discord_slash/error.py
--- a/discord_slash/error.py
+++ b/discord_slash/error.py
@@ -48,3 +48,8 @@ class CheckFailure(SlashCommandError):
     """
     Command check has failed.
     """
+
+class IncorrectType(SlashCommandError):
+    """
+    Type passed was incorrect
+    """
diff --git a/discord_slash/model.py b/discord_slash/model.py
--- a/discord_slash/model.py
+++ b/discord_slash/model.py
@@ -176,8 +176,9 @@ def from_type(cls, t: type):
         :return: :class:`.model.SlashCommandOptionType` or ``None``
         """
         if issubclass(t, str): return cls.STRING
-        if issubclass(t, int): return cls.INTEGER
         if issubclass(t, bool): return cls.BOOLEAN
+        # The check for bool MUST be above the check for integers as booleans subclass integers
+        if issubclass(t, int): return cls.INTEGER
         if issubclass(t, discord.abc.User): return cls.USER
         if issubclass(t, discord.abc.GuildChannel): return cls.CHANNEL
         if issubclass(t, discord.abc.Role): return cls.ROLE
diff --git a/discord_slash/utils/manage_commands.py b/discord_slash/utils/manage_commands.py
--- a/discord_slash/utils/manage_commands.py
+++ b/discord_slash/utils/manage_commands.py
@@ -2,7 +2,7 @@
 import inspect
 import asyncio
 import aiohttp
-from ..error import RequestFailure
+from ..error import RequestFailure, IncorrectType
 from ..model import SlashCommandOptionType
 from collections.abc import Callable
 
@@ -144,7 +144,7 @@ async def remove_all_commands_in(bot_id,
 
 def create_option(name: str,
                   description: str,
-                  option_type: int,
+                  option_type: typing.Union[int, type],
                   required: bool,
                   choices: list = None) -> dict:
     """
@@ -157,6 +157,11 @@ def create_option(name: str,
     :param choices: Choices of the option. Can be empty.
     :return: dict
     """
+    if not isinstance(option_type, int) or isinstance(option_type, bool): #Bool values are a subclass of int
+        original_type = option_type
+        option_type = SlashCommandOptionType.from_type(original_type)
+        if option_type is None:
+            raise IncorrectType(f"The type {original_type} is not recognized as a type that Discord accepts for slash commands.")
     return {
         "name": name,
         "description": description,


Test patch: