Type Adapters¶
TypeAdapters
are a part of the execution chain. They are used to adapt the input of a slash command to the correct type needed to invoke the method.
Default Type Adapters¶
JDA-Commands provides the following type adapters by default:
- all primitive types and their respective wrapper types
- User
- Member
- Role
- Channel and subtypes (e.g. StageChannel, NewsChannel, etc.)
You can add any of these types as a parameter to your slash command methods. See Command Options for details. These default types will be mapped to the most fitting option type. You can find the mapping here.
Writing Own Type Adapters¶
Example
Tip
If your type adapter is simple enough, you could also just use lambda expressions:
Your own types will always be mapped to OptionType.STRING
. If the type adapting fails (an empty Optional
is returned)
an error message will be sent to the user:
You can customize this error message, find more about it here.