Level System [Aoi.js]
This will show you Code for Level System and will Explain how it works! Your Folder should be like this:
- Level-System
- rank.js
- leaderboard.js
- auto-levelup.js
- enable-level.js
- disable-level.js
- earn-xp.js
Code
index.js - Variables
client.variables({ levelsystem: "false", xp: "0", level: "1", (You can change starter level to 1, 5, 10 ...) xplimit: "10" (You can change it to whatever you want, but going above 100 is not recommended!)})
variables.js - Variables
Requires require("./variables.js")(client);
in index.js
module.exports = (client) => { client.variables({ levelsystem: "false", xp: "0", level: "1", (You can change starter level to 1, 5, 10 ...) xplimit: "10" (You can change it to whatever you want, but going above 100 is not recommended!) }, "main"); };
enable-level.js
module.exports ={ name: "enable-level", code: ` $title[Level System - Enabled] $description[ Unlocked Commands: \`d!rank\`, \`d!leaderboard\`] $color[Orange] $setGuildVar[levelsystem;true] $onlyIf[$getGuildVar[levelsystem]==false;Already Enabled, Disable it by typing \`d!disable-level\`] $onlyPerms[administrator;Access Denied]`}
disable-level.js
module.exports ={ name: "disable-level", code: ` $title[Level System - Disabled] $description[ Locked Commands: \`d!rank\`, \`d!leaderboard\`] $color[Orange] $setGuildVar[levelsystem;false] $onlyIf[$getGuildVar[levelsystem]==true;Already Disabled, Enable it by typing \`d!enable-level\`] $onlyPerms[administrator;Access Denied]`}
earn-xp.js
module.exports ={ name: "$alwaysExecute", code: ` $setUserVar[xp;$sum[$getUserVar[xp];1]] $onlyIf[$getGuildVar[levelsystem]==true;]`}
auto-levelup.js
module.exports ={ name: "$alwaysExecute", code: ` $description[$username has Leveled UP! New Level: $getUserVar[level]] $color[Orange] $setUserVar[xplimit;$sum[$getUserVar[xplimit];20]] $setUserVar[level;$sum[$getUserVar[level];1]] $onlyIf[$getUserVar[xp]==$getUserVar[xplimit];]`}
rank.js
module.exports ={ name: "rank", code: ` $title[$username's Rank] $description[ Level: \`$getUserVar[level]\` XP: \`$getUserVar[xp]\` / \`$getUserVar[xplimit]\`] $color[Orange] $onlyIf[$getGuildVar[levelsystem]==true;Level System not Enabled]`}
leaderboard.js
module.exports ={ name: "leaderboard", aliases: ["lb"], code: ` $title[$guildName's Leaderboard] $description[1;$userLeaderBoard[$guildID;level;asc;{top} - {username} - {value} Level;10;1;main]] $description[2;$userLeaderBoard[$guildID;xp;asc;{top} - {username} - {value};10;1;main]] $color[1;Orange] $color[2;Orange] $onlyIf[$getGuildVar[levelsystem]==true;Level System not Enabled]`}
Explanation
- This section will try its best to explain how each code works above, things you should know.
Enable-Level
How do I execute this command?
[prefix]enable-level
How does it work?
When you (user) execute the command, your Bot will first check if you have Administrator Permission. If you have, Bot will return “Level System - Enabled” or something similar.
After that Bot will set Variable’s(levelsystem) Value to true
for that guild, allowing users of that guild to use the Level System!
Disable-Level
How do I execute this command?
[prefix]disable-level
How does it work?
To shorten it, it is same as enable-level but instead of setting the Variable Value to true
it sets it to false
instead. Then users can’t use Level / Ranking system anymore in that guild!
Earn-XP
How do I execute this command?
- You execute it when you type an message and send it in guild
- Requires Level / Ranking to be enabled
How does it work?
When you send Message, Bot detects it and uses $setUserVar to set your new XP, inside of $setUserVar[] we will use $sum on “value” field, like $sum[50;50] that will equal 100 and will set to 100, but $sum[$getUserVar[xp];1]
this will get Current Value and increase it by 1!
- You can add an $cooldown[2s;] of 2s and no error message so users cannot spam xp
Auto-Level UP
How do I execute this command?
- You execute it when you type an message
- Requires Level / Ranking to be enabled
How does it work?
Concept is same as for Earn-XP, we use $sum and $setUserVar to reset XP and increase XP Limit while also increasing their Level by 1.
However most important thing here is $onlyIf, $onlyIf[$getUserVar[xp]==$getUserVar[xplimit];]
this $onlyIf checks if user has reached the XP limit, if they did not command will not execute, but if they did it will execute and return an Level UP! Message.
Rank
How do I execute this command?
[prefix]rank
How does it work?
- Command itself is pretty simple, we use $getUserVar to get User’s XP, Limit and Level (1,2,3…).
$onlyIf[$getGuildVar[levelsystem]==true;Level System not Enabled]
Check if Level / Ranking is Enabled, if its not it will return Error Message, if its Enabled it will return information.
Leaderboard
How do I execute this command?
[prefix]leaderboard
How does it work?
- We use an function called $userLeaderboard
$userLeaderBoard[guildID;variable;order?;custom?;list?;page?;table?]
we fill out required things Guild ID and Variable which we want leaderboard for, other things are optional - Check aoi.js Documentation for more information about function
End
- Thanks to anyone who is still Following me on Youtube Channel and actually uses codes I make, appreciate that!
- Hope you liked this simple Level(Ranking) System!
Credits
JosipFX - Made Code & Video