Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 2 additions & 35 deletions discord/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .member import Member
from .abc import GuildChannel
from .role import Role
from .enums import SlashCommandOptionType

class SlashCommand:
type = 1
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
31 changes: 31 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down