About command params
Closed this issue · 1 comments
Summary
Suggesting an commands.Parameter class
What is the feature request for?
discord.ext.commands
The Problem
Currently, assigning names, descriptions, and autocomplete to command options is very ugly and messy. Take this as an example:
@commands.command(
add_slash_command=True,
param_descriptions={
"a": "The first number",
"b": "The second number",
"mode": "The math mode",
},
autocomplete_params=["mode"],
)
async def addition(
self, ctx: commands.Context, a: int, b: int, mode: str = "normal"
):
"""
An example addition command.
"""
if mode == "scuffed":
await ctx.send(f"{a} + {b} = {a // -b}")
await ctx.send(f"{a} + {b} = {a + b}")
The Ideal Solution
I propose a params
attribute to discord.Ext.commands.Command
. Here would be the syntax for it:
@commands.command(
add_slash_command=True,
params=(
commands.Param("a", description="The first number"),
commands.Param("b", description="The second number"),
commands.Param("mode", description="The math mode", autocomplete=True),
)
)
async def addition(
self, ctx: commands.Context, a: int, b: int, mode: str = "normal"
):
"""
An example addition command.
"""
if mode == "scuffed":
await ctx.send(f"{a} + {b} = {a // -b}")
await ctx.send(f"{a} + {b} = {a + b}")
This discord.Ext.commands.Param
would roughly function as:
(class) Param(self, name: str, *, description: Optional[str] = None, autocomplete: Optional[bool] = False)
The Current Solution
No response
Additional Context
No response
This kind of system brings up an interesting disparity between the parameters of the slash command and the parameters of the message command. The message command system uses type hinting to describe how inputs are parsed, but with slash commands the inputs are pre-parsed for you.
With something like what you've described here it would make sense to also include the TYPE of the parameter, but that ALSO is incompatible with the previous message-based system of argument parsing. I'm not super sure of how to go about doing this.
I do agree that the current system is kinda cumbersome, but I want to think more on this before committing to a new design choice.