Skip to content

Commit b5e18ae

Browse files
committed
Implemented connector support for auto option generator
1 parent 9144820 commit b5e18ae

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

discord_slash/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def add_slash_command(self,
361361
description = description or getdoc(cmd)
362362

363363
if options is None:
364-
options = manage_commands.generate_options(cmd, description)
364+
options = manage_commands.generate_options(cmd, description, connector)
365365

366366
_cmd = {
367367
"func": cmd,
@@ -423,7 +423,7 @@ def add_subcommand(self,
423423
self.commands[base].allowed_guild_ids.append(x)
424424

425425
if options is None:
426-
options = manage_commands.generate_options(cmd, description)
426+
options = manage_commands.generate_options(cmd, description, connector)
427427

428428
_cmd = {
429429
"func": None,

discord_slash/cog_ext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def ping(self, ctx: SlashContext):
4040
def wrapper(cmd):
4141
desc = description or inspect.getdoc(cmd)
4242
if options is None:
43-
opts = manage_commands.generate_options(cmd, desc)
43+
opts = manage_commands.generate_options(cmd, desc, connector)
4444
else:
4545
opts = options
4646

@@ -111,7 +111,7 @@ async def group_say(self, ctx: SlashContext, text: str):
111111
def wrapper(cmd):
112112
desc = description or inspect.getdoc(cmd)
113113
if options is None:
114-
opts = manage_commands.generate_options(cmd, desc)
114+
opts = manage_commands.generate_options(cmd, desc, connector)
115115
else:
116116
opts = options
117117

discord_slash/utils/manage_commands.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def create_option(name: str,
171171
}
172172

173173

174-
def generate_options(function: Callable, description: str = "No description.") -> list:
174+
def generate_options(function: Callable, description: str = "No description.", connector: dict = None) -> list:
175175
"""
176176
Generates a list of options from the type hints of a command.
177177
You currently can type hint: str, int, bool, discord.User, discord.Channel, discord.Role
@@ -181,8 +181,11 @@ def generate_options(function: Callable, description: str = "No description.") -
181181
182182
:param function: The function callable of the command.
183183
:param description: The default argument description.
184+
:param connector: Kwargs connector of the command.
184185
"""
185186
options = []
187+
if connector:
188+
connector = {y: x for x, y in connector.items()} # Flip connector.
186189
params = iter(inspect.signature(function).parameters.values())
187190
if next(params).name in ("self", "cls"):
188191
# Skip 1. (+ 2.) parameter, self/cls and ctx
@@ -204,7 +207,8 @@ def generate_options(function: Callable, description: str = "No description.") -
204207
required = not args[-1] is type(None)
205208

206209
option_type = SlashCommandOptionType.from_type(param.annotation) or SlashCommandOptionType.STRING
207-
options.append(create_option(param.name, description or "No Description.", option_type, required))
210+
name = param.name if not connector else connector[param.name]
211+
options.append(create_option(name, description or "No Description.", option_type, required))
208212

209213
return options
210214

0 commit comments

Comments
 (0)