Skip to content

Velen Message Component

Mihou edited this page Jul 15, 2021 · 10 revisions

🗨️ Velen Message Component

This is the part of Velen where you can customize the no permission, no role and rate-limited message. First of all, we have to understand how the Configurable Message API of Velen works.

🧱 Configurable Message

To understand the Configurable Message API of Velen, there are two things you have to take note. One, all messages follows the same format which means all messages have to go through something like .ofNormal(...) or .ofEmbed.

Secondly, all configurable messages have two types:

  • Normal: A message that is sent as text with an expected return type being of String.
  • Embed: A message that is sent as an embed with an expected return type being of EmbedBuilder.

The two methods that all configurable messages share are:

  • ofEmbed(...): Creates an Embed Message that will be sent when event is triggered.
  • ofNormal(...): Creates an ordinary text message that will be sent when event is triggered.

⛔ No Permission Message

An example of configuring the No Permission message of Velen is:

Normal Message

Velen velen = Velen.builder().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!"))
                  .build();

Embed Message

Velen velen = Velen.builder().setNoPermissionMessage(VelenPermissionMessage.ofEmbed(
                                  (permission, user, channel, command) -> new EmbedBuilder()
                                  .setTitle("You do not meet the permissions!")
                                  .setDescription("You need the permission(s): " + permission
                                  .stream().map(PermissionType::name).collect(Collectors.joining(", ")) 
                                  + " to use this command!")))
                  .build();

And after setting that, if a user attempts to execute a command without the exact permission to use it, the bot will reply (Normal):

You need the permission(s): PERMISSION_A, PERMISSION_B, PERMISSION_C to use this command!

🚷 No Role Message

You can also opt to change the No Role message as well, an example would be:

Normal Message

Velen velen = Velen.builder().setNoRoleMessage(VelenRoleMessage.ofNormal(
                     (roles, user, channel, command) -> "You do not have the role(s): " 
                     + roles + " to use this command!"))
                   .build();

Embed Message

Velen velen = Velen.builder().setNoRoleMessage(VelenRoleMessage.ofEmbed(
                     (roles, user, channel, command) -> new EmbedBuilder()
                        .setTitle("You do not meet the roles!")
                        .setDescription("You need the role(s): " + roles + " to use this command!")))
                   .build();

What Velen would do when the user does not have the role to use the command would send a message like (Normal):

You need the role(s): @ROLE_A, @ROLE_B to use this command!

Naturally, we have all ALLOWED_MENTIONS disabled which means the bot will not ping the roles mentioned.

🚫 Rate-limited Message

You can also opt to change the You are currently rate-limited message as well, an example would be:

Normal Message

Velen velen = Velen.builder().setRatelimitedMessage(VelenRatelimitMessage.ofNormal(
                     (remainingSeconds, user, channel, command) -> "Please wait " + remainingSeconds + 
                     " seconds to use this command!"))
                  .build();

Embed Message

Velen velen = Velen.builder().setRatelimitedMessage(VelenRatelimitMessage.ofEmbed(
                     (remainingSeconds, user, channel, command) -> new EmbedBuilder()
                         .setTitle("You are rate-limited!")
                         .setDescription("You are currently rate-limited for " + remainingSeconds + " seconds!"))
                     ).build();