Skip to content

Create @Option.Bind annotation #12

@azzerial

Description

@azzerial

Create the @Option.Bind annotation that can be placed before a method parameter (of a @Slash.Handler) and that binds the option to the parameter. This allows the option to be passed as typed parameter to shortcut the traditional JDA way of getting the options.

Note: In case the options cannot be mapped to the parameter type, the method would not be called.

Note: In case an option is a union type (as for the MENTIONABLE), it would be possible to create multiple @Slash.Handler methods with different parameter types for the option. The api would then call the most appropriate method.

Note: A default value (for non-required options only) should be added to the @Option.Bind.

Example

For a simple kick command, the current way of writing it

@Slash.Handler()
public void kick(SlashCommandEvent event) {
    final User user = Objects.requireNonNull(event.getOption("user")).getAsUser();
    final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString();

    ...
}

would become

@Slash.Handler()
public void kick(SlashCommandEvent event, @Option.Bind("user") User user, @Option.Bind("reason") String reason) {
    ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions