JDA-Utilities icon indicating copy to clipboard operation
JDA-Utilities copied to clipboard

Commands dont Work

Open xXFlyingBananaXx opened this issue 3 years ago • 9 comments

Hello, I tried to make Commands, but it didnt Work. I didnt found any issue Report that has kind of the same Problem, this is not an JDA Issue its an JDA-Utilities Issue. I hvae the latest Version of both, the Bot is running on a BungeeCord Plugin but that worked fine with just JDA.

So the Real Problem i guess is that the Command doesnt get registered because even on the help command it doesnt show the Command, i tried to Debug with a simple sout but it didnt Print.

Here are my 2 Classes: Main Class:


    public static void start(){



        try {
            JDABuilder bot = JDABuilder.createDefault("");
            CommandClientBuilder builder = new CommandClientBuilder();
            builder.setPrefix("f.");
            builder.setHelpWord("help");
            builder.setAlternativePrefix("f1.");
            builder.setOwnerId("847627635324354631");
            builder.addCommand(new ServerCommand());
            builder.setActivity(Activity.playing("Joine jetzt 'Tsukimi.de'"));
            builder.setStatus(OnlineStatus.ONLINE);

            CommandClient client = builder.build();
            bot.addEventListeners(client);
            bot.build();




            BCSystems.plugin.getProxy().getConsole().sendMessage(TextComponent.fromLegacyText("§9The Discord Bot has been successfully started"));
        }catch (LoginException e){
            e.printStackTrace();
        }

    }


}```

My Command Class:

public class ServerCommand extends Command { public ServerCommand(){ this.name = "server"; this.aliases = new String[]{"s","ip"}; this.help = "Dieser Command gibt Informationen über den Server aus";

}
@Override
protected void execute(CommandEvent event) {
    List<String> list = new ArrayList<>();

    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setTitle("Tsukimi.de");
    embedBuilder.setDescription("Joine Jetzt mit der 1.8.8 - 1.16.5");
    BCSystems.plugin.getProxy().getPlayers().forEach(proxiedPlayer -> {
        list.add(proxiedPlayer.getDisplayName());
    });
    if (list.isEmpty()){
        return;
    }else {
        embedBuilder.addField("Online Spieler",list.toString(),true);
    }

    System.out.println("Command geht eig?");
    event.getMessage().reply(embedBuilder.build()).queue();
}

}

I hope you can help me, thanks!

xXFlyingBananaXx avatar Jun 05 '21 12:06 xXFlyingBananaXx

While i can't tell you what's wrong with your code, all i can say is that this is certainly not a JDA-Utilities issue. You should ask for help on the JDA Discord in the jda-utilities channel.

Xirado avatar Jun 05 '21 13:06 Xirado

Well i did ask and they said its probably a Bug and i should do my own Command thing so :/

xXFlyingBananaXx avatar Jun 05 '21 13:06 xXFlyingBananaXx

Hey there,

I'm not sure if that's the actual problem but you're checking here "JDABuilder" it should be "JDA" JDABuilder bot = JDABuilder.createDefault("");

JDA bot = JDABuilder.createDefault("");

Destitution-SC avatar Jun 05 '21 20:06 Destitution-SC

Hey there,

I'm not sure if that's the actual problem but you're checking here "JDABuilder" it should be "JDA" JDABuilder bot = JDABuilder.createDefault("");

JDA bot = JDABuilder.createDefault("");

Nope, he is building the JDABuilder in the code

Xirado avatar Jun 05 '21 20:06 Xirado

Oh yea right, i see. Then I'm not sure what's the problem.

Destitution-SC avatar Jun 05 '21 20:06 Destitution-SC

You should fix the formatting of your issue. Parts of the code blocks are messed up

Andre601 avatar Jun 05 '21 21:06 Andre601

JDA bot = JDABuilder.createDefault("");

That wouldn't even compile. It is just a bad naming.

DManstrator avatar Jun 05 '21 22:06 DManstrator

Your command should work. The only issue is there there is a return block in

 if (list.isEmpty()){
        return;
    }else {

soo if the BCSystem returned an empty list your bot wouldn't respond at all. There it may not be that your bot is not working it might be due to the return statement that stops the command from proceeding. If not there shouldn't be any other issue, if the above is not your problem try checking your bots intends maybe something is messed up there

Bluedragonplayz2 avatar Jun 10 '21 01:06 Bluedragonplayz2

If the returned players is empty for some reason your list will also stay empty.

Sanduhr32 avatar Jun 10 '21 08:06 Sanduhr32