Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Pre‐defined Context Resolvers

Kevin edited this page Oct 9, 2023 · 4 revisions

ACF Javacord comes with some pre-defined command context resolvers for generic Javacord. The objects listed below are supported for both types of commands, while message commands have additional pre-defined context resolvers. To see these, see Message Command Context Resolvers.

  • DiscordApi (Issuer-only)
  • Message (Issuer-only)
  • Server (Issuer-only)
  • Users
    • User
    • Member
  • Channels
    • ChannelType
    • ServerChannel
    • ServerTextChannel
    • ServerVoiceChannel
    • ServerForumChannel
    • ServerThreadChannel
    • ChannelCategory
  • Emojis
    • Emoji
    • UnicodeEmoji
    • CustomEmoji
    • KnownCustomEmoji

Additional objects

Member

ACF Javacord comes with a Member object, which represents a User within a server's context. It contains all server-specific information and methods of a User, and can be used as a command parameter:

@Default
public void onCommand(JavacordCommandEvent event, Member member) {
    // This displays either the user's nickname within the server of the context, or the username
    // of the user who invoked the command.
    event.reply(member.getDisplayName());
}

When a Member parameter is flagged with @Flags("other"), the user invoking the command must provide a member while entering it.

@Default
public void onCommand(JavacordCommandEvent event, @Flags("other") Member member) {
    // This displays the display name of the given member.
    event.reply(member.getDisplayName());
}

When it is annotated with @BotUser, the Member object of the bot will be provided.

@Default
public void onCommand(JavacordCommandEvent event, @BotUser Member member) {
    // This displays the display name of the bot.
    event.reply(member.getDisplayName());
}

UnicodeEmoji

ACF Javacord also comes with a UnicodeEmoji object, which allows for creating Emoji objects out of Unicode emojis, and can also be used as a command parameter:

@CommandAlias("unicodetest")
public class UnicodetestCommand extends BaseCommand {

    @Default
    public void onCommand(JavacordCommandEvent event, UnicodeEmoji emoji) {
        // This will reply with the emoji itself.
        // E.g. "e!unicodetest :smile:" or "e!unicodetest \uD83D\uDE04" or "e!unicodetest 😄" would all result in the same emoji being used in the reply.
        event.reply(emoji.getMentionTag());
    }
}