Interface Context


  • public interface Context
    Context of a bot command.
    • Method Detail

      • getCommand

        Command getCommand()
        Gets the command that created this context.
        Returns:
        the original command
      • getEvent

        discord4j.core.event.domain.message.MessageCreateEvent getEvent()
        Gets the message create event associated to this command.
        Returns:
        the event
      • getArgs

        List<String> getArgs()
        Gets the arguments of the command.
        Returns:
        the args
      • getBot

        Bot getBot()
        Gets the bot instance.
        Returns:
        the bot
      • getPrefixUsed

        String getPrefixUsed()
        Gets the prefix used in the command that created this context.
        Returns:
        the prefix used
      • reply

        reactor.core.publisher.Mono<discord4j.core.object.entity.Message> reply​(String message)
        Sends a message in the same channel the command was sent.
        Parameters:
        message - the message content of the reply
        Returns:
        a Mono emitting the message sent
      • reply

        reactor.core.publisher.Mono<discord4j.core.object.entity.Message> reply​(java.util.function.Consumer<? super discord4j.core.spec.MessageCreateSpec> spec)
        Sends a message in the same channel the command was sent. This method supports advanced message construction.
        Parameters:
        spec - the message content of the reply
        Returns:
        a Mono emitting the message sent
      • setVar

        void setVar​(String name,
                    Object val)
        Adds a variable in this context. If a variable of the same name exists, it is overwritten.
        Parameters:
        name - the name of the variable
        val - the value of the variable
      • setVarIfNotExists

        void setVarIfNotExists​(String name,
                               Object val)
        Adds a variable in this context. If a variable of the same name exists, nothing happens.
        Parameters:
        name - the name of the variable
        val - the value of the variable
      • getVar

        <T> T getVar​(String name,
                     Class<T> type)
        Gets the value of a variable.
        Type Parameters:
        T - the variable type
        Parameters:
        name - the variable name
        type - the type of the variable
        Returns:
        the value of the variable, or null if not found or exists in the wrong type
      • getVarOrDefault

        <T> T getVarOrDefault​(String name,
                              T defaultVal)
        Gets the value of a variable. If not found, the provided default value is returned instead.
        Type Parameters:
        T - the variable type
        Parameters:
        name - the variable name
        defaultVal - the default value to return if not found
        Returns:
        the value of the variable, or the default value if not found or exists in the wrong type
      • getGuildSettings

        reactor.core.publisher.Mono<Map<Plugin,​Map<String,​String>>> getGuildSettings()
        Gets the guild settings
        Returns:
        an unmodifiable Map containing the guild settings keys and their associated values.
      • setGuildSetting

        reactor.core.publisher.Mono<Void> setGuildSetting​(String key,
                                                          String val)
        Edits an entry of the guild settings.
        Parameters:
        key - the setting key
        val - the setting value
        Returns:
        a Mono that completes when successfully updated
        Throws:
        NoSuchElementException - if no entry is found for the given key
        IllegalArgumentException - if the given value is not accepted by the entry
        UnsupportedOperationException - if this method is called in a context that is outside of a Discord guild
      • fork

        Context fork​(List<String> newArgs)
        Creates a new Context that is an exact copy of this one, but with different arguments.
        Parameters:
        newArgs - the new arguments that the copy will get
        Returns:
        a new Context