Skip to content

Useful Examples

Random Values

Random Number

Just a simple command using random function that will print a random number from 0 to 100:

JuniperBot Template
You got: **{{ random(0, 100) }}**

Random Text

Using the same random function you can print a random text message:

JuniperBot Template
{{ random(['Hi!', 'Hello!', 'Its nice to meet you!']) }}

Random Number using input range

Let's make it a bit more complicated. How about a custom command with random numbers based on member's input:

JuniperBot Template
{% require arguments.get(1) returning 'Please specify minimal value' %}
{% require arguments.get(2) returning 'Please specify maximal value' %}

{{ member }}, you got **{{ random(arguments.get(1), arguments.get(2)) }}**

This command checks if member entered first and second arguments as minimal and maximal values of random range and prints the result using those values.

Random Number using input range with validation

Previous example has one drawback. If the user specifies non-numbers or the maximum value is less than the minimum, the template will return an error that doesn't look very clear to the member.

We need to make sure that the input has the valid numbers and that the maximum value is greater than the minimum. This can be done as follows:

JuniperBot Template
{% set minumum = arguments.get(1) %}
{% set maximum = arguments.get(2) %}

{% require minumum returning 'Please specify minimal value!' %}
{% require minumum is number returning 'Minimal value must be a number!' %}
{% require maximum returning 'Please specify maximal value!' %}
{% require maximum is number returning 'Maximal value must be a number!' %}

{% if (minumum > maximum) %}
  {% return 'Maximal value must be greater than minimal!' %}
{% endif %}

{{ member }}, you got **{{ random(minumum, maximum) }}**

Random Picture

Okay and here is the BOSS FIGHT. Let's make our own command with random picture just like !fox, !dog, !cat with some fun message with member mention. Here is the !pet command:

JuniperBot Template
{% set targetMember = arguments.targetMember %}

{% require targetMember returning 'Who needs pets?' %}

{% if (targetMember.id == member.id) %}
	{% return 'Petting yourself?' %}
{% endif %}

{%- global gif = random([
  'https://images-ext-1.discordapp.net/external/yOicyNxjyB_y1Cf3hCgsePnL36oofd1qjsyFRjDWOzc/https/cdn.weeb.sh/images/SyFmqkFwW.gif?width=432&height=243',
  'https://images-ext-2.discordapp.net/external/ab1ICw2oaiDaG8Y0DwlPClP7xG54Ie4kKcaFtn7Q8LU/https/cdn.weeb.sh/images/SktIxo20b.gif?width=486&height=273',
  'https://images-ext-2.discordapp.net/external/5ol3M2-FsEvm81oZXbS8rZdEdevG3qqDJ9faicEDrw8/https/cdn.weeb.sh/images/rJMskkFvb.gif?width=450&height=247',
  'https://images-ext-2.discordapp.net/external/jFzBryOm4sSnuGD1FDOhtzGW52leLqh6UmIR5l6meZw/https/cdn.weeb.sh/images/SJLaWWRSG.gif?width=486&height=274',
  'https://images-ext-1.discordapp.net/external/PzOpIvj5jAgz6bcEq7jwtXPbKgmSV-dVKSvPc__CsCQ/https/cdn.weeb.sh/images/rkl1xJYDZ.gif?width=486&height=304',
  'https://images-ext-2.discordapp.net/external/sSZt42u8v8sWfZ5pg1NNIhnR7eEzmDXRIm93_GZG6yU/https/cdn.weeb.sh/images/Hkccqp4A-.gif?width=450&height=350',
  'https://images-ext-2.discordapp.net/external/GN3TW6pXl-zupZ7Do5h4o1Pnm6ZA_2wj9RUqydghUW8/https/cdn.weeb.sh/images/Sk2FyQHpZ.gif?width=450&height=253',
  'https://images-ext-1.discordapp.net/external/8tlbO-PtNvDizaijNJSJrzY1-lGprkAw_aO95H196dQ/https/cdn.weeb.sh/images/r1Y5L6NCZ.gif?width=486&height=270',
  'https://images-ext-2.discordapp.net/external/Ml2iTnfjVuHGP-Lkz88WrGKJCv1cJ7UikuE2yvt3XgI/https/cdn.weeb.sh/images/rJWRykFvZ.gif?width=540&height=304',
  'https://images-ext-1.discordapp.net/external/mVv4CiNvJjVBP6PbQgzleqysb31wA-P3p7v02S8jpfc/https/cdn.weeb.sh/images/ryXj1JKDb.gif?width=432&height=243'
]) -%}

**{{ member.nickname }}** pets **{{ targetMember.nickname }}**! 

This commands expects a member mention or ID as input and will return an error if mention was not specified. It will also check if you want to pet yourself and will return a message about it.

The random function is used to pick a random gif from the list. Note that we used a global tag so we could use that variable in other Message Template field.

In this case, we need to add an image so we will switch Message Template to Embed mode and paste this global variable into Embed's "Image Url" field:

JuniperBot Template
{{ gif }}

Other

Buttons

This example describes how to create a ban command with confirmation do we really want to ban specifier member or not. Buttons will be used for confirmation. Each tab describes each command action you should create and set up.

Action Type: "Send message"

JuniperBot Template
{% set targetMember = arguments.targetMember %}

{% require targetMember returning 'Specify the member!' %}

{% do parameters.store('memberId', (targetMember.id)) %}
{% do parameters.store('args', arguments.after(2)) %}
{% do button('PRIMARY', 'acceptBtn', 'Confirm', '✅', '59f7f318-17c9-45b8-be61-33c1f89d54ba') %}
{% do button('SECONDARY', 'cancelBtn', 'Cancel', '❎', 'c18e2b11-2760-464b-b9f4-f04b7db349bc') %}

Do you really want to ban member {{targetMember}}?

The last argument of button functions are UUIDs of "Ban" and "Cancel" actions accordingly. They are unique, so you must replace them with UUIDs of your own actions you've just created.

Embed Message

JuniperBot Template
{% do channel
    .createEmbed()
    .withContent('Content outside the embed')
    .withTitle('Title', 'https://juniper.bot')
    .withDescription('Oh, hi!')
    .appendDescription('\nHow are you?')
    .withDate(1587713425964)
    .withColor('ffff00')
    .withThumbnail(member.avatarUrl)
    .withImage('https://i.pinimg.com/originals/a4/41/6e/a4416e024d691af3a2971e4114a6da7f.png')
    .withAuthor(member.nickname)
    .withFooter('Huff, bye!', member.avatarUrl)
    .addField('First field', 'Ah! A value of the first field', true)
    .addField('Second field', 'Something here too', true)
    .addReaction(':fox_face:')
    .addButton('LINK', 'https://juniper.bot/', 'Website', '🦊')
    .send()
%}

Adding Role to Yourself

It is possible to create a custom command that will add a role to the member and will print something or not, for example:

JuniperBot Template
{% do member.addRole(390472433003659264) %}

This example uses addRole method of Member which accepts an ID of role.

Adding Role to Mentioned Member

We can also add a role to mentioned member as follows:

JuniperBot Template
{% set targetMember = arguments.targetMember %}
{% require targetMember returning 'Please specify a member to give The Guardian role!' %}

{% do targetMember.addRole(390472433003659264) %}

This example differs from the previous one. The role is given to the member mentioned with the command, not to the one who invoked it.

Ranking Role Rewards

Ranking level up announcement messages have a variables to print added and/or removed roles, let's print them:

JuniperBot Template
{{ member }}, you reached a new level: **{{ member.rank.level }}**!
{% if (not empty(rolesAdded)) -%}
You've got new roles: {{ join(rolesAdded) }}
{%- endif -%}
{% if (not empty(rolesRemoved)) %}
You've lost roles: {{ join(rolesRemoved) }}
{% endif %}

This template prints added and removed roles only if there was something to add and remove at this level.

It is better to use this template in Embed Content Template so you will not ping the members that have those roles.

Report Command

It is possible to create a simple report command as follows:

  1. Create a new text channel available only to bot and moderators;
  2. Create a new custom command;
  3. In custom command select the channel you created previously as target channel and switch to Embed mode;
  4. Insert following to Embed Content Template:
JuniperBot Template
{% set targetMember = arguments.targetMember %}

{% global reason = arguments.after(2) %}

{% require targetMember and reason returning 'Please specify an ID or mention of member and the report description' %}

A [report]({{ message.jumpUrl }}) was created for {{ targetMember }}:

{{ reason }}

{% do sourceChannel.sendMessage(format('%s, your report was sent! Thank you.', member)) %}

This command requires a violators ID or mention and the report description that will be sent to moderators.

The message template itself is sent to the created report channel so it responds to the command that the report was successfully sent.

All rights sniffed.