Skip to content

Commit 6e0d077

Browse files
authored
Remove positional arg support (#214)
* remove positional arg support * add migration info
1 parent fb5be46 commit 6e0d077

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

discord_slash/client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,10 +1182,7 @@ async def invoke_command(self, func, ctx, args):
11821182
:param args: Args. Can be list or dict.
11831183
"""
11841184
try:
1185-
if isinstance(args, dict):
1186-
await func.invoke(ctx, **args)
1187-
else:
1188-
await func.invoke(ctx, *args)
1185+
await func.invoke(ctx, **args)
11891186
except Exception as ex:
11901187
if not await self._handle_invoke_error(func, ctx, ex):
11911188
await self.on_slash_command_error(ctx, ex)

docs/migration.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@ Migration
22
+++++++++
33
This page contains instructions on how to migrate between versions with breaking changes.
44

5+
Migrate To V2.0.0
6+
=================
7+
This update introduced component support, and removed support for positional arguments.
8+
9+
To resolve long standing issues with the library, we have removed positional argument support. From now on, only keyword arguments are supported. As such you may need to update your commands.
10+
11+
Put simply, you will need to make sure your command parameters are named the same as your options, or use the connector argument.
12+
13+
14+
Example
15+
*******
16+
17+
.. code-block:: python
18+
19+
# Example 1
20+
@slash.slash(name="example_command", options=[
21+
manage_commands.create_option(name="opt_one", [...]),
22+
manage_commands.create_option(name="opt_two", [...])
23+
])
24+
async def example_command(ctx, opt_one, opt_two):
25+
await ctx.send(f"{opt_one=}, {opt_two=}")
26+
27+
# Example 2
28+
@slash.slash(name="example_command", options=[
29+
manage_commands.create_option(name="opt_one", [...]),
30+
manage_commands.create_option(name="opt_two", [...])
31+
],
32+
connector={"opt_one": "optone",
33+
"opt_two": "opttwo"})
34+
async def example_command(ctx, optone, opttwo):
35+
await ctx.send(f"{optone=}, {opttwo=}")
36+
537
Migrate To V1.1.0
638
==================
739
Changes that you'll need to make in this version are mainly because of a new ui from discord, more info `here <https://github.com/discord/discord-api-docs/pull/2615>`_
@@ -24,7 +56,7 @@ We suggest deferring if you might take more than three seconds to respond, but i
2456
``ctx.channel.send`` does **not** count as responding.
2557

2658
Example
27-
--------
59+
*******
2860

2961
.. code-block:: python
3062

0 commit comments

Comments
 (0)