Skip to content

Velen Main Component

Mihou edited this page Nov 17, 2021 · 2 revisions

✔️ Velen Component

The Velen component is, by far, the simplest to make with the exception of PrefixManager and Ratelimiter with an example of creating the component being:

Velen velen = Velen.builder()
  // Sets the default cooldown time of the command if no cooldown is specified.
  .setDefaultCooldownTime(Duration.ofSeconds(10))

  // Sets the default prefix that Velen will use (this will be overriden by Prefix Manager).
  .setDefaultPrefix("v.")

  // Sets the message to be sent once every ratelimit cycle if the user is rate-limited.
  .setRatelimitedMessage(VelenRatelimitMessage.ofNormal((remainingSeconds, user, channel, command) -> "Please wait " + remainingSeconds + " seconds to use this command!"))

  // Set the message to be sent if the user doesn't have all the permissions needed to use the command. (default)
  .setNoPermissionMessage(VelenPermissionMessage.ofNormal((permission, user, channel, command) -> "You do not have the permission(s): " 
                     + permission.stream().map(PermissionType::name).collect(Collectors.joining(", ")) + " to use this command!"))

  // Set the message to be sent if the user doesn't have the proper roles to use the command. (default)
 .setNoRoleMessage(VelenRoleMessage.ofNormal((roles, user, channel, command) -> "You do not have the role(s): " + roles + " to use this command!"))

  // Sets the prefix manager which is a more advanced default prefix which allows you to fetch
  // prefixes from a database for per-server prefixes, example below.
  // Key is equals to the server id, you should only use this if you are using a database to store
  // per-server prefixes.
  .setPrefixManager(new VelenPrefixManager("v.", key -> prefixes.get(key)))
  .build();

You can also use the default settings of Velen which can be retrieved through the one-liner method:

Velen velen = Velen.ofDefaults();

After building the Velen instance, you can then attach it to your DiscordApi instance through the following:

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