Messages¶
Messages are a central part of JDA-Commands, they include content send to the user via the reply API, strings used in framework annotations and modals and much more.
To provide the best user experience possible, JDA-Commands comes included with localization, support for placeholders and Unicode and app emojis. In many places in the framework, these feature are applied implicitly.
Resolution¶
The features listed above are all pipelined together with help of the MessageResolver.
They are applied to the string provided by the user in following order:
The resulting string is then send to Discord or returned to the user.
Usage¶
Instead of manually using the MessageResolver
class, JDA-Commands allows for implicit resolution
of messages in many common please. These include:
- Component API including the corresponding annotations like
@Button,@Modaletc. - Embed API
- Reply API, for example the string content of a message
ReplyableEvent#reply(String, Entry...)
If you are using localization, please take a look at implicit localization.
Warning
Message resolution of content in MessageCreateData is not supported implicitly.
You have to use MessageResolver
to resolve such messages.
Adding custom String Resolvers¶
Sometimes it's necessary to introduce custom resolution logic. JDA-Commands provides JDACProperty#STRING_RESOLVER
(configurable by JDACBuilder#stringResolver(Resolver...)) allowing the user to add own implementations of
Resolver<String>.
Each Resolver has a priority affecting the order in which all registered
String Resolvers are applied by MessageResolver. A lower priority is applied first (e.g. I18n runs after PlaceholderResolver).
The default Resolvers have the following priorities:
PlaceholderResolver= 1000I18n= 2000EmojiResolver= 3000
Example¶
public class URLResolver implements Resolver<String> {
public String resolve(String msg, Locale locale, Map<String, @Nullable Object> placeholders) {
return msg.replace("JDAC_GH", "https://github.com/Kaktushose/jda-commands");
}
public int priority() {
return 4000; // should run after all built in resolvers
}
}