Class CommandManager

  • All Implemented Interfaces:
    net.dv8tion.jda.api.hooks.EventListener

    public final class CommandManager
    extends java.lang.Object
    implements net.dv8tion.jda.api.hooks.EventListener
    Represents a command manager.
    • Constructor Detail

      • CommandManager

        public CommandManager​(@NotNull
                              @NotNull net.dv8tion.jda.api.JDA jda)
      • CommandManager

        public CommandManager​(@NotNull
                              @NotNull net.dv8tion.jda.api.JDA jda,
                              @NotNull
                              @NotNull CommandSettings settings)
      • CommandManager

        public CommandManager​(@NotNull
                              @NotNull net.dv8tion.jda.api.sharding.ShardManager shardManager)
      • CommandManager

        public CommandManager​(@NotNull
                              @NotNull net.dv8tion.jda.api.sharding.ShardManager shardManager,
                              @NotNull
                              @NotNull CommandSettings settings)
    • Method Detail

      • registerCommand

        public void registerCommand​(@NotNull
                                    @NotNull Command command)
        Registers the specified command into the manager.
        Parameters:
        command - the command you wish to register
      • registerCommands

        public void registerCommands​(@NotNull
                                     @NotNull Command... commands)
        Registers the specified command array into the manager
        Parameters:
        commands - the commands you want to register
      • registerCommands

        public void registerCommands​(@NotNull
                                     @NotNull java.util.List<Command> commands)
        Registers the specified command list into the manager
        Parameters:
        commands - the commands you want to register
      • registerCommand

        public void registerCommand​(@NotNull
                                    @NotNull RegisteredCommand registeredCommand)
        Registers the specified RegisteredCommand object into the manager.
        Parameters:
        registeredCommand - the command you want to register
      • addMessageEventSubscription

        public void addMessageEventSubscription​(@NotNull
                                                @NotNull java.util.function.Consumer<MessageEventSubscriber> subscriber)
        Adds a MessageEventSubscriber, called if no commands occur while handling events.
        Parameters:
        subscriber - subscriber
      • getSettings

        @NotNull
        public @NotNull CommandSettings getSettings()
        Returns the settings for all inbuilt things, handlers and stuff.
        Returns:
        settings
      • setSettings

        public void setSettings​(@NotNull
                                @NotNull CommandSettings settings)
        Sets a new settings
        Parameters:
        settings - the new settings you wish to set
      • getRegisteredCommands

        public java.util.List<RegisteredCommand> getRegisteredCommands()
        Returns a unmodifiable list of the registered commands.
        Returns:
        registered commands
      • getCommand

        public java.util.Optional<RegisteredCommand> getCommand​(@NotNull
                                                                @NotNull java.lang.String alias)
        Retrieves the first command found which has the specified alias as alias or the specified alias is the command's name.
        Parameters:
        alias - the command name/alias for the command you wish to get
        Returns:
        optional of registered command if present, empty optional otherwise
      • findCommand

        @NotNull
        public @NotNull java.util.List<RegisteredCommand> findCommand​(@NotNull
                                                                      @NotNull java.lang.String startsWith)
        Finds the command(s) with the specified startsWith argument.
        Parameters:
        startsWith - string which starts with a command alias
        Returns:
        list of commands found
      • dispatchCommand

        @Deprecated
        public boolean dispatchCommand​(@NotNull
                                       @NotNull net.dv8tion.jda.api.JDA jda,
                                       @NotNull
                                       @NotNull net.dv8tion.jda.api.entities.Guild guild,
                                       @NotNull
                                       @NotNull net.dv8tion.jda.api.entities.TextChannel channel,
                                       @NotNull
                                       @NotNull net.dv8tion.jda.api.entities.Member member,
                                       @NotNull
                                       @NotNull java.lang.String commandLine)
        Deprecated.
        command dispatchers can't really be a thing, especially in JDA's ecosystem. If you want to dispatch commands manually, do it, but JDCF won't maintain such a breakable method.
        Executes the specified command line with the specified arguments. When dispatched, the author and member of the command are the JDA.getSelfUser() and Guild.getSelfMember(). DISCLAIMER: This method does not check for permissions, meaning that when you call it you mean "I want this command executed no matter what".
        Parameters:
        jda - the jda instance from which the command should be executed
        guild - the guild where the command should be executed
        channel - the channel, used for the command to reply with response
        member - the member for which the command is going to watch parameters
        commandLine - the command line to execute
        Returns:
        execution success state
      • onEvent

        public void onEvent​(@Nonnull
                            net.dv8tion.jda.api.events.GenericEvent generic)
        Specified by:
        onEvent in interface net.dv8tion.jda.api.hooks.EventListener