use of net.dv8tion.jda.api.JDABuilder in project c0debaseBot by Biospheere.
the class Codebase method initializeJDA.
/**
* @return The {@link JDA} instance fot the current session
* @throws Exception
*/
private JDA initializeJDA() throws Exception {
try {
final JDABuilder jdaBuilder = JDABuilder.createDefault(System.getenv("DISCORD_TOKEN"));
jdaBuilder.setEnabledIntents(GatewayIntent.getIntents(GatewayIntent.ALL_INTENTS));
jdaBuilder.setMemberCachePolicy(MemberCachePolicy.ALL);
jdaBuilder.setActivity(Activity.playing("auf c0debase"));
jdaBuilder.addEventListeners(new GuildReadyListener(this));
return jdaBuilder.build().awaitReady();
} catch (Exception exception) {
logger.error("Encountered exception while initializing JDA!");
throw exception;
}
}
use of net.dv8tion.jda.api.JDABuilder in project Saber-Bot by notem.
the class ShardManager method restartShard.
/**
* Shuts down and recreates a JDA shard
* @param shardId (Integer) shardID of the JDA shard
*/
public void restartShard(Integer shardId) throws LoginException, InterruptedException {
if (this.isSharding()) {
// do not handle shards not assigned to the current instance of the bot
if (this.jdaShards.containsKey(shardId)) {
// shutdown the shard
Logging.info(this.getClass(), "Shutting down shard-" + shardId + ". . .");
this.getShard(shardId).shutdownNow();
this.jdaShards.remove(shardId);
// configure the builder from the template
Logging.info(this.getClass(), "Starting shard-" + shardId + ". . .");
JDABuilder shardBuilder;
if (shardId == 0) {
shardBuilder = this.builder.useSharding(shardId, shardTotal);
} else {
shardBuilder = this.builder.useSharding(shardId, shardTotal);
}
// restart the shard (asynchronously)
JDA shard = shardBuilder.build();
this.jdaShards.put(shardId, shard);
}
} else {
Logging.info(this.getClass(), "Restarting bot JDA. . .");
this.jda.shutdownNow();
this.jda = this.builder.build().awaitReady();
}
}
Aggregations