You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat💥: rework slash command parameter processing
This both makes it much faster and allows for proper parsing of Annotated.
This does break a few niche cases though - most notably, CMD_* are gone.
* revert: don't touch autocomplete
* chore: remove breakpoint comment
* refactor: use annotated class directly
---------
Co-authored-by: Astrea49 <25420078+Astrea49@users.noreply.github.com>
The library provides `CMD_ARGS`, `CMD_AUTHOR`, `CMD_BODY`, and `CMD_CHANNEL` to get the arguments, the author, the body, and the channel of an instance of a command based on its context. While you can do these yourself in the command itself, having this as an argument may be useful to you, especially for cases where you only have one argument that takes in the rest of the message:
72
-
73
-
```python
74
-
# this example is only viable for prefixed commands
75
-
# the other CMD_* can be used with slash commands, however
There are also `Converter`s that represent some Discord models that you can subclass from. These are largely useful for prefixed commands, but you may find a use for them elsewhere.
69
+
There are `Converter`s that represent some Discord models that you can subclass from. These are largely useful for prefixed commands, but you may find a use for them elsewhere.
84
70
85
71
A table of objects and their respective converter is as follows:
86
72
@@ -109,3 +95,33 @@ A table of objects and their respective converter is as follows:
109
95
|`Role`|`RoleConverter`|
110
96
|`PartialEmoji`|`PartialEmojiConverter`|
111
97
|`CustomEmoji`|`CustomEmojiConverter`|
98
+
99
+
100
+
## `typing.Annotated`
101
+
102
+
Using `typing.Annotated` can allow you to have more proper typehints when using converters:
103
+
104
+
```python
105
+
classUpperConverter(Converter):
106
+
asyncdefconvert(ctx: BaseContext, argument: str):
107
+
return argument.upper()
108
+
109
+
# Slash Command:
110
+
@slash_command(name="upper", description="Sends back the input in all caps.")
For slash commands, `interactions.py` will find the first argument in `Annotated` (besides for the first argument) that are like the converters in this guide and use that.
127
+
For prefixed commands, `interactions.py` will always use the second parameter in `Annotated` as the actual converter/parameter to process.
`interactions.py` will use the second parameter in `Annotated` as the actual converter.
273
-
274
258
#### `Greedy`
275
259
276
260
The `Greedy` class, included in this library, specifies `interactions.py` to keep converting as many arguments as it can until it fails to do so. For example:
0 commit comments