diff --git a/discord/commands.py b/discord/commands.py index 6e0bf6c5af..626ed94350 100644 --- a/discord/commands.py +++ b/discord/commands.py @@ -32,6 +32,7 @@ from .member import Member from .abc import GuildChannel from .role import Role +from .enums import SlashCommandOptionType class SlashCommand: type = 1 @@ -80,40 +81,6 @@ def __eq__(self, other): and other.description == self.description ) -class SlashCommandOptionType(Enum): - custom = 0 - #sub_command = 1 - #sub_command_group = 2 - string = 3 - integer = 4 - boolean = 5 - user = 6 - channel = 7 - role = 8 - mentionable = 9 - number = 10 - - @classmethod - def from_datatype(cls, datatype): - if isinstance(datatype, str): - return cls.string - if isinstance(datatype, str): - return cls.integer - if isinstance(datatype, str): - return cls.boolean - if isinstance(datatype, Member): - return cls.user - if isinstance(datatype, GuildChannel): - return cls.channel - if isinstance(datatype, Role): - return cls.role - if isinstance(datatype, None): # FIXME uhm - return cls.mentionable - if isinstance(datatype, float): - return cls.number - return cls.custom - - class Option: def __init__(self, type, /, **kwargs): self.name = kwargs.pop("name", None) @@ -138,7 +105,7 @@ def __init__(self, name, value=None): self.value = value or name def to_dict(self): return { - "name":self.name", + "name":self.name, "value":self.value } diff --git a/discord/enums.py b/discord/enums.py index af8ee2b0a0..a95264e282 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -588,6 +588,37 @@ class NSFWLevel(Enum, comparable=True): safe = 2 age_restricted = 3 +class SlashCommandOptionType(Enum): + custom = 0 + #sub_command = 1 + #sub_command_group = 2 + string = 3 + integer = 4 + boolean = 5 + user = 6 + channel = 7 + role = 8 + mentionable = 9 + number = 10 + + @classmethod + def from_datatype(cls, datatype): + if isinstance(datatype, str): + return cls.string + if isinstance(datatype, str): + return cls.integer + if isinstance(datatype, str): + return cls.boolean + if isinstance(datatype, Member): + return cls.user + if isinstance(datatype, GuildChannel): + return cls.channel + if isinstance(datatype, Role): + return cls.role + if isinstance(datatype, float): + return cls.number + return cls.custom + T = TypeVar('T')