I am new to JDA discord bot and encountered a problem with the builder.build().getShardManager() method. At some points in my code I need the shardManager but I dont know how to get it. I found out that getShardManager() can be called on an JDA object (here: JDABuilder.build()) but it only returns a null reference. (The main class crashes at line 4 with a nullpointerexception) (without the shardmanager the bot works)
How do I obtain the shardmanager correctly?
this.builder = JDABuilder.createDefault(TOKEN);
builder.addEventListeners(new CommandHandler());
shardManager = this.builder.build().getShardManager();
shardManager.setActivity(Activity.playing("Do smth."));
You should use the JDA Object and not the ShardManager.
try something like this:
this.builder = JDABuilder.createDefault(TOKEN);
builder.addEventListeners(new CommandHandler());
JDA jda = this.builder.build();
jda.getPresence().setActivity(Activity.playing("Hello World!"));
You can also set the Activity before building the Bot
this.builder = JDABuilder.createDefault(TOKEN);
builder.addEventListeners(new CommandHandler());
builder.setActivity(Activity.playing("Hello World!"));
JDA jda = this.builder.build();