Skip to content

Getting Started

Mihou edited this page Nov 21, 2021 · 18 revisions

🎈 Getting Started with Velen

This part of the wiki aims to get you comfortable with using Velen as fast as possible by guiding you one step at a time over how to use the library. The library's design takes a lot of inspiration from Javacord which means, if you are already using Javacord, then most if not all of the features of Velen will be easy for you to get into.

We highly recommend understanding Javacord and Discord Bot Development first (along with Java) before getting into Velen as this library uses plentiful of Lambdas and a little bit of Optionals along with CompletableFutures which aren't for pure beginners of Java.

πŸ”’ Additional

Velen has its own CLI which although is limited can create .velen and .vecomp files for you, read more here: Velen CLI

πŸ’­ Setting Up Velen

To setup Velen, you first have to create a Velen component (Read more at Velen Component Page) which is the main component of Velen which is in charge of handling and processing everything. The component is extremely configurable with plenty of options to use which we will be going through one by one later, but first, let us create a Velen component through the builder:

Velen velen = Velen.builder().build();

Simple, right? Buuuuut! That is not what Velen is for, the purpose of Velen is to simplify the process of making commands in Javacord while also being flexible which is why those configuration options exists. Let us first get into the simplest part which is changing the default cooldown (rate-limiter) of all commands.

⏲️ Rate-limiters (a.k.a Cooldowns)

The default rate-limiter or cooldown of all Velen commands can only be configured during the building process of Velen, there are only two settings which you can change and those are the message sent (when the user first attempts to execute the command while on cooldown) and the default cooldown time of all the commands (which is used if the command does not have a cooldown specified).

Changing the default cooldown time is simply adding one line to the builder:

Velen velen = Velen.builder()
                   .setDefaultCooldownTime(Duration.ofSeconds(10))
                   .build();

By default, the default cooldown time is of ten seconds but you can change it per-command and globally.

πŸ– Configuring Messages & Prefix Manager

As of Velen 2.0, these two categories on this page has been deprecated in favor of their own Wiki Page which is a more organized, simpler and more detailed understanding of each categories:

πŸ‘¨πŸ»β€βš–οΈ Blacklisting (ignoring users)

Velen supports blacklisting users from triggering commands on the bot which you can easily setup by adding a Blacklist on the builder (non-persistent blacklist example):

Velen velen = Velen.builder().setBlacklist(new VelenBlacklist()).build();

If you want to blacklist a user, all you have to do is simply:

velen.getBlacklist().add(userId);

To remove, all you have to do is:

velen.getBlacklist().remove(userId);

The two methods above will only modify the internal blacklist and won't touch your database which means, if you are using a persistent database, additional means are needed. For example, if you are making changes onto your database through a method like add, you have to use either methods as well to apply the changes to internal list.

You can also opt to refreshing it which uses the loader you set when building the blacklist, the method to refresh the user is simply:

velen.getBlacklist().refresh(userId);

BUT the method above as I mentioned, requires a loader which you can quickly build when constructing the blacklist, for example (MongoDB with a Helper Class):

new VelenBlacklist(aLong -> MongoDB.collection("blacklists", "someBot").find(Filters.eq("userId", aLong)).first() != null);

The reason why we are using != null on the above is because the blacklist expects a boolean as a return, and so, the database is expected to be something similar like: If the user is on the database, then the user is blacklisted otherwise not.

We recommend placing null or not adding setBlacklist() at all if you are not using the blacklist since a null blacklist is a signal to the application that we are not using a blacklist (to stop the application from heading to the blacklist and getting the value and instead assume no one is blacklisted).

πŸ”š Finalizing Velen

After building your Velen instance, you can finally attach it to Javacord to start listening. All you have to do to make Velen work after building it is simply .addListener(velen) on your DiscordApiBuilder, example:

Velen velen = Velen.builder().setDefaultPrefix("v.").build();
velen.loadFrom("examples");

DiscordApi api = new DiscordApiBuilder().setToken(token)
                 .addListener(velen).login().join();

πŸ’― Building Commands

As of Velen 3.0, creating commands in the newer way has become a bit more complicated in a sense, please read its dedicated wiki page instead: Building Commands!

πŸ”š πŸ”š Ending

The guide here are all simple implementations of how to get started with Velen, if you want to learn more about the components, we highly recommend reading the other parts of the GitHub Wiki