Installing & Preparing Nexus - ShindouMihou/Nexus GitHub Wiki

To begin the installation of Nexus, visit Jitpack, and pick the specific release you wish to install. Alternatively, you can opt for a particular branch or commit and follow the provided instructions on the same page.

Nexus comes with default configurations that adhere to the most basic standards. However, before proceeding, there are a few prerequisites that must be addressed. One of these prerequisites involves managing connections and disconnections with the shard manager. The framework employs its own sharding manager, which intelligently allocates diverse tasks to separate shards, eliminating the need for you to consistently include a shard parameter. This necessitates a method for the framework to access these shards.

This can be accomplished by following these steps when initializing a shard:

val shard: DiscordApi = ...
Nexus.sharding.set(shard)

Here's a demonstration of how this can be implemented:

// Example One: Non-sharded
val shard = DiscordApiBuilder()
    .setToken(...)
    .addListener(Nexus)
    .login()
    .join()
Nexus.sharding.put(shard)

// Example Two: Sharded
DiscordApiBuilder()
    .setToken(...)
    .addListener(Nexus)
    .setTotalShards(1)
    .loginAll()
    .forEach { future -> 
       future.thenAccept { shard -> 
          Nexus.sharding.set(shard)
          // Additional essential tasks like onShardLogin() can be performed here as well  
       } 
    }

Don't forget to include the addListener line to direct events to Nexus:

DiscordApiBuilder()
    .addListener(Nexus)

Important! When disconnecting shards, it's crucial to inform Nexus about your intention to remove the shard. Add the following line before executing the actual disconnect:

Nexus.sharding.remove(shard.currentShard)