Git Product home page Git Product logo

jcommands's Introduction

JCommands Maven Central

With this Javacord extension you can create Slash Commands on your Discord server within 1 minute with built-in

  • input validating,
StringArgument<Integer> stringArgument = new StringArgument<>("number", "A number", Integer.class);  
stringArgument.getArgumentValidator().when(RegexPredicate.notValidFor("\\d+")).thenRespond(event -> {  
    event.getResponder().respondNow()  
        .setContent("The input is not a number!")  
        .respond();  
});  
  • value converting,
stringArgument.convertResult(value -> Integer.parseInt(value));  
  • autocompleting and
StringArgument<String> searchArgument = new StringArgument<>("search", "Start typing", String.class);  
SearchAutocomplete searchAutocomplete = new SearchAutocomplete(SearchAutocomplete.SearchType.CONTAINS, Arrays.asList(  
    "just some words like hello world"  
    .split(" ")  
))  
.ignoreCase();  
searchArgument.addAutocomplete(searchAutocomplete);  
  • concatenating
command.addConcatenator(new StringConcatenator<>(" ", String.class), stringArgument, searchArgument);  

There are so many useful pre-written argument types that can be used while creating a command.

Example command

This command is created just with about 50 lines of code including the response and error handling. It has a validated argument with regex, an argument that has two different values that the user can choose from, a number argument that has a range validation, a normal user mention argument, a normal channel mention argument and an optional attachment argument with size and extension validation.

Example

You can find the full code here that runs a bot with the example command above.

Wiki

You can find all the information about how to use JCommands on the Wiki page.

Dependencies

This is a Javacord extension. Javacord is a Discord bot framework and it so much easier to create bots with it.

Usage

Replace {VERSION} with one of the released versions from 6.0.0 (the latest recommended)

Maven

<dependency>  
    <groupId>io.github.s3ns3iw00</groupId>  
    <artifactId>jcommands</artifactId>  
    <version>{VERSION}</version>  
</dependency>  

Gradle

dependencies {  
    implementation 'io.github.s3ns3iw00.jcommands:{VERSION}'  
}  

Contact

If you found a bug, or you just want a new feature in the next version, don't hesitate to report it on the issues page or feel free to open a pull request. You can contact me through discord: senseydev

jcommands's People

Contributors

danielgellert avatar s3ns3iw00 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

katnova mrtuxa

jcommands's Issues

Autocompletes for arguments with the same name for different commands are overridden

I have a slashcommand with two subcommands: subscribe and unsubscribe. Both have an identically named argument.

The first one to load has this code:

        StringArgument<String> targetNameArgument = new StringArgument<>(
                "name", "The name of the target", String.class);
        SearchAutocomplete searchAutocomplete = new SearchAutocomplete(
                SearchAutocomplete.SearchType.CONTAINS, targetStringList
        ).ignoreCase().limit(10).sort(SearchAutocomplete.SortType.ASCENDING).minCharToSearch(2);
        targetNameArgument.addAutocomplete(searchAutocomplete);
        addArgument(targetNameArgument);

The second has this code:

        StringArgument<String> targetNameArgument = new StringArgument<>(
                "name", "The name of the target", String.class);
        Autocomplete autocomplete = new Autocomplete(subscriptions);
        targetNameArgument.addAutocomplete(autocomplete);
        addArgument(targetNameArgument);

When the bot runs, BOTH commands' name arg has the autocomplete from the second command. If I comment out the autocomplete for the second command, the first command's autocomplete works correctly. If I rename the argument to be unique, both work correctly. Is it somehow storing them by name globally and overwriting the original one even though it is on a different command?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.