Interface AutoCompletable


public interface AutoCompletable
Interface for commands that handle the CommandAutoCompleteInteractionEvent.

 public class PingCommand extends SlashCommand implements AutoCompletable {

     public PingCommand() {
         setCommandData(Commands.slash("ping", "Ping someone").addOption(OptionType.STRING, "user-id", "The user's id", true, true));
     }

     @Override
     public void execute(@Nonnull SlashCommandInteractionEvent event) {
         OptionMapping mapping = event.getOption("user-id");
         String userId = mapping.getAsString();
         event.replyFormat("Ping! <@%s>", userId).queue();
     }

     @Override
     public void handleAutoComplete(@Nonnull CommandAutoCompleteInteractionEvent event, @Nonnull AutoCompleteQuery target) {
         if (target.getName().equals("user-id")) {
             List<Member> members = event.getGuild().getMembers().stream().limit(25).collect(Collectors.toList());
             List<Command.Choice> choices = new ArrayList<>(25);
             for (Member member : members) {
                 choices.add(new Command.Choice(member.getUser().getAsTag(), member.getId()));
             }
             event.replyChoices(AutoCompleteUtils.filterChoices(event, choices)).queue();
         }
     }

 }
 
Since:
v1.4
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    handleAutoComplete(net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event, net.dv8tion.jda.api.interactions.AutoCompleteQuery target)
    Method that must be overridden for all commands that handle auto-complete interactions.
  • Method Details

    • handleAutoComplete

      void handleAutoComplete(@Nonnull net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event, @Nonnull net.dv8tion.jda.api.interactions.AutoCompleteQuery target)
      Method that must be overridden for all commands that handle auto-complete interactions.
      Parameters:
      event - the CommandAutoCompleteInteractionEvent.
      target - the AutoCompleteQuery input.