Skip to content

Commit 764dac4

Browse files
authored
Merge pull request #44 from mavit/ApplicationCommandOptionType
New enumeration, SlashCommandOptionType
2 parents 34f5f04 + 42f6fd6 commit 764dac4

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

discord_slash/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
from .client import SlashCommand
12+
from .model import SlashCommandOptionType
1213
from .model import SlashContext
1314
from .utils import manage_commands
1415

discord_slash/client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,10 @@ async def _pick(ctx, choice1, choice2): # Command with 1 or more args.
427427
428428
.. code-block:: python
429429
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.
430+
{"option_role": "role", # For key put name of the option and for value put type of the option.
431+
"option_user": SlashCommandOptionType.USER, # Also can use an enumeration member for the type
432+
"option_user_two": 6, # or number
433+
"option_channel": "CHANNEL"} # or upper case string.
433434
434435
:param name: Name of the slash command. Default name of the coroutine.
435436
:type name: str
@@ -565,15 +566,15 @@ async def process_options(self, guild: discord.Guild, options: list, auto_conver
565566
types = {
566567
"user": 0,
567568
"USER": 0,
568-
6: 0,
569+
SlashCommandOptionType.USER: 0,
569570
"6": 0,
570571
"channel": 1,
571572
"CHANNEL": 1,
572-
7: 1,
573+
SlashCommandOptionType.CHANNEL: 1,
573574
"7": 1,
574575
"role": 2,
575576
"ROLE": 2,
576-
8: 2,
577+
SlashCommandOptionType.ROLE: 2,
577578
"8": 2
578579
}
579580

discord_slash/model.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from discord.ext import commands
44
from . import http
55
from . import error
6+
from enum import IntEnum
67

78

89
class SlashContext:
@@ -282,3 +283,17 @@ def invoke(self, *args):
282283
:return: Coroutine
283284
"""
284285
return self.func(self.cog, *args)
286+
287+
288+
class SlashCommandOptionType(IntEnum):
289+
"""
290+
Equivalent of `ApplicationCommandOptionType <https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype>`_ in the Discord API.
291+
"""
292+
SUB_COMMAND = 1
293+
SUB_COMMAND_GROUP = 2
294+
STRING = 3
295+
INTEGER = 4
296+
BOOLEAN = 5
297+
USER = 6
298+
CHANNEL = 7
299+
ROLE = 8

docs/quickstart.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Let's do some more complicated things:
7272
7373
import discord
7474
from discord_slash import SlashCommand
75+
from discord_slash import SlashCommandOptionType
7576
from discord_slash.utils import manage_commands
7677
7778
client = discord.Client(intents=discord.Intents.all())
@@ -87,7 +88,7 @@ Let's do some more complicated things:
8788
async def _ping(ctx):
8889
await ctx.send(content=f"Pong! ({client.latency*1000}ms)")
8990
90-
@slash.slash(name="echo", guild_ids=guild_ids, options=[manage_commands.create_option("string", "A random string.", 3, True)])
91+
@slash.slash(name="echo", guild_ids=guild_ids, options=[manage_commands.create_option("string", "A random string.", SlashCommandOptionType.STRING, True)])
9192
async def _echo(ctx, string):
9293
await ctx.send(content=string)
9394

0 commit comments

Comments
 (0)