Giter Site home page Giter Site logo

Comments (15)

Kaktushose avatar Kaktushose commented on June 16, 2024

is there a way to make a commandautocompleteevent work properly?

Currently no, but there will be a way in the future. Choices have already been implemented because they are part of the command definition, but autocomplete events are a separate element.

Currently I don't have any time to code, but autocomplete will be added within the next release(s).

Closing this issue since this feature is already part of my internal roadmap

from jda-commands.

Kaktushose avatar Kaktushose commented on June 16, 2024

implemented with 4.0.0-alpha.4

from jda-commands.

Scyye avatar Scyye commented on June 16, 2024

image
image

am i doin somethin wrong?

from jda-commands.

Kaktushose avatar Kaktushose commented on June 16, 2024

you need to specify the command name and not the parameter name. for you exmaple this would be package list search

from jda-commands.

Scyye avatar Scyye commented on June 16, 2024

so would i need to do separate things for each of the commands that all have a community param?;

from jda-commands.

Kaktushose avatar Kaktushose commented on June 16, 2024

You can specify multiple commands per AutoComplete, but yes

from jda-commands.

Scyye avatar Scyye commented on June 16, 2024

could you give an example?

from jda-commands.

Kaktushose avatar Kaktushose commented on June 16, 2024
@Interaction
public class AutoCompleteTest {

    private final String[] words = new String[]{"apple", "apricot", "banana", "cherry", "coconut", "cranberry"};

    @SlashCommand("fruit")
    public void onFruitCommand(CommandEvent event, @Param("fruit to find") String name) {
        event.reply("You selected %s", name);
    }

    @SlashCommand("food")
    public void onFoodCommand(CommandEvent event, @Param("fruit to find") String name) {
        event.reply("You selected %s", name);
    }

    @AutoComplete({"fruit", "food"})
    public void onAutoComplete(AutoCompleteEvent event) {
        event.replyChoices(Stream.of(words)
                .filter(word -> word.startsWith(event.getValue()))
                .map(word -> new Command.Choice(word, word))
                .collect(Collectors.toList())
        );
    }
}

Also be aware of the AutoCompleteEvent#getName() method to retrieve the name of the parameter, in case you have more than one parameter per command.

from jda-commands.

Scyye avatar Scyye commented on June 16, 2024

this following code doesnt seem to be workin?

@AutoComplete(value = {"package search", "package author", "package info"})
public void onAutocompleteCommunity(AutoCompleteEvent event) {
    if (event.getName().equals("community"))
        event.replyChoices(Stream.of(Bot.bot.tsja.getCommunities())
            .filter(community -> community.getIdentifier().startsWith(event.getValue()))
            .map(community -> new Command.Choice(community.getIdentifier(), community.getIdentifier()))
            .collect(Collectors.toList())
    );
}

any clue?

from jda-commands.

Kaktushose avatar Kaktushose commented on June 16, 2024

I've used the following code to test your use case on my machine and it worked fine:

@Interaction
public class AutoCompleteTest {

    private final String[] words = new String[]{"apple", "apricot", "banana", "cherry", "coconut", "cranberry"};

    @SlashCommand(value = "package search")
    public void onCommand1(CommandEvent event, String community) {
        event.reply("You selected %s", community);
    }

    @SlashCommand(value = "package author")
    public void onCommand2(CommandEvent event, String community) {
        event.reply("You selected %s", community);
    }

    @SlashCommand(value = "package info")
    public void onCommand3(CommandEvent event, String community) {
        event.reply("You selected %s", community);
    }

    @AutoComplete(value = {"package search", "package author", "package info"})
    public void onAutoComplete(AutoCompleteEvent event) {
        if (event.getName().equals("community")) {
            event.replyChoiceStrings(Stream.of(words)
                    .filter(word -> word.startsWith(event.getValue()))
                    .collect(Collectors.toList())
            );
        }
    }
}

Please provide your debug log file and also double check that the error is not caused by your getCommunities method, because i have no influence on your bot code

from jda-commands.

Kaktushose avatar Kaktushose commented on June 16, 2024

While working on a feature that allows to only use the top level name, in this case "package" to register all sub commands I've encountered a bug, which sometimes leads to autocomplete not being registered correctly. This got fixed with commit adbdc41 and will be shipped with the next release.

Here is the maven snippet to use this commit as long as the release isn't ready:

<dependency>
    <groupId>com.github.Kaktushose</groupId>
    <artifactId>jda-commands</artifactId>
    <version>adbdc4190e</version>
</dependency>

please let me know if this fixes your issue

from jda-commands.

Scyye avatar Scyye commented on June 16, 2024

using that version seems to disable the commands?
but also not?

image
(its not the apple profile picture, and its in the server)

but then,
image
with this at the end of my start

Bot.bot.jda.retrieveCommands().queue(commands -> {
    commands.forEach(command -> {
        System.out.println(command.getName());
    });
});

from jda-commands.

Kaktushose avatar Kaktushose commented on June 16, 2024

will be fixed with the next commit

from jda-commands.

Kaktushose avatar Kaktushose commented on June 16, 2024

0199890 should fix this

from jda-commands.

Scyye avatar Scyye commented on June 16, 2024

Confirmed to be working, thank you!

from jda-commands.

Related Issues (20)

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.