Skip to content

Installing & Preparing Nexus

Miu edited this page Aug 15, 2023 · 2 revisions

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)

To get started with Nexus, we recommend reading the following in chronological:

  1. Installation & Preparing Nexus
  2. Designing Commands
  3. Command Interceptors
  4. Additional Features (Subcommand Router, Option Validation)
  5. Context Menus
  6. Command Synchronization

You may want to read a specific part of handling command and middleware responses:

You can also read about additional features of Nexus:

You can read about synchronizing commands to Discord:

For more additional performance:

Additional configurations:

Clone this wiki locally