-
-
Notifications
You must be signed in to change notification settings - Fork 1
Nexus.R
React Native + Svelte for Discord Bots. Nexus.R (React) is a Kotlin-only feature that enables developers to respond to slash commands more intuitively akin to web development. In addition, Nexus.R supports a simple and minimal state system (writable) that enables you to update the Discord message by simply changing a writable's value.
- Write-once, Use Everywhere
- Nexus.R allows you to easily reuse responses whether it was written for slash commands or for messages with hardly any changes.
- States in Discord Bot
- Nexus.R introduces the infamous states of the JavaScript world into Discord bots, allowing you to create messages that will re-render itself upon different state changes, just like a reactive website!
- Webdev-like Feel
- In order to make Discord bot development more accessible to even web developers, we've made the feature feels like writing web code (JSX) but simpler!
Nexus.R is simple enough for most developers that you can simply read the code and you'll understand it. If you prefer to learn by reading examples, we recommend reading the examples.
In this wiki page, we'll try to go in-depth into Nexus.R and how we can use it effectively to build a beautiful and reactive Discord bot. Nexus.R is easier to understand for web developers who are familiar with JSX or Svelte as this essentially is the same but for Kotlin Discord bots and that's what makes it beautiful, but before we begin with our guide, we have to understand one thing and that is: Nexus.R will never be as performant and memory efficient as manually doing things yourself, but it will be more easier on the developer experience.
To expand upon the above statement, it's important to acknowledge that Nexus.R breaks the traditional philosophy of Nexus in which abstractions are kept at a minimal. Nexus.R builds many abstractions upon the Javacord way in order to optimize the most for developer experience, which in turn, means it creates a lot of objects, which allocates a bit more memory and uses more time.
According to our testing though, Nexus.R doesn't impact a lot as the code is designed enough that it doesn't create enough objects that it slows down things, in fact, most rendering completes in about 1-10 milliseconds and that's very tiny. Now that we know such fact, if you still want to use Nexus.R to favor better developer experience, then let's start reading!
Nexus.R supports practically everything where you can create a message whether it'd be an Interaction, a User, a Text Channel or anything that can be messaged. In this example, we'll be looking at things more towards Slash Commands, but you can read the examples to see how it'd look for other methods.
You can start the journey by entering into Nexus.R (React) scope by calling the R method.
fun onEvent(event: NexusCommandEvent) {
event.R { }
}In this scope, we can start defining the message by creating how it looks inside the render function. How about we create a simple embed that tells people that this message was rendered with Nexus.R, it should also be yellow in color and have a title and a timestamp that should be when the message was sent?
fun onEvent(event: NexusCommandEvent) {
event.R {
render {
Embed {
Title("Rendered with Nexus.R")
SpacedBody(
p("This message was rendered with Nexus.R.")
)
Color(java.awt.Color.YELLOW)
Timestamp(Instant.now())
}
}
}
}With that, the entire command is ready to go and you can simply execute the command and it should render the following message:

But that's pretty simple though, how about we go even further and dive into reactivity and buttons?
All information in this wiki was written during v1.2.0, we recommend updating to that version if you are below, or creating an issue in GitHub, updating the wiki if the current information is missing, outdated or lacking.
To get started with Nexus, we recommend reading the following in chronological:
- Installation & Preparing Nexus
- Designing Commands
- Command Interceptors
- Additional Features (Subcommand Router, Option Validation)
- Context Menus
- 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:
- Subcommand Routing
- Option Validation
- Express Way (shard management)
- Inheritance
- Feather Pagination
- Nexus.R
You can read about synchronizing commands to Discord:
For more additional performance:
Additional configurations: