1.0.0 • Published 2 years ago

@elaraa/discord-xp v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Installation

To install the package, you can easily do it by typing the command below:

+ npm install @elaraa/discord-xp@latest

To update to the latest version to our package, just do

+ npm update @elaraa/discord-xp

If you need help or you encountered an error while using our package, feel free to join our Discord server and we'll try to assist as soon as possible!

Changelogs

// Updates coming soon!

Starting up

To start using this package, you will need to do these two steps first.

  • You will need to require the package using the example code below:
const Xp = require('@elaraa/discord-xp')

After that you can now connect to your Mongoose database. Put this below the line where you imported the package

Xp.connect('mongodb://...');

Functions

• createUser — Creates a new user on the database if it doesn't exist.

Xp.createUser(<UserID - String>, <GuildID - String>)

• deleteUser — Remove all the data of a user in the database if data exist.

Xp.deleteUser(<UserID - String>, <GuildID - String>)

• deleteGuild — Deletes all the data of the server in the database.

Xp.deleteGuild(<GuildID - String>)

• resetGuild — Resets all the settings for the guild in the database (XP will not reset)

Xp.resetGuild(<GuildID - String>)

• fetchLeadboard — Fetches the leaderboard from the guild Id provided

Xp.fetchLeadboard(<GuildID - String>, <Ranks - Number>)

• fetchUser — Fetch an individual user from the database

Xp.fetchUser(<UserID - String>, <GuildID - String>)

• xpFor — Calculate how many XP needed for a level

Xp.xpFor(<Level - Number>)

• xpLevel — Calculate how many levels is equal to the XP given.

Xp.xpLevel(<XP - Number>)

• setXp — Set the user's XP manually

Xp.setXp(<UserID - String>, <GuildID - String>, <XP - Number>)

• setLevel — Set the user's level manually

Xp.setLevel(<UserID - String>, <GuildID - String>, <Level - Number>)

• addXp — Add XP to the given user

Xp.addXp(<UserID - String>, <GuildID - String>, <XP - Number>)

• addLevel — Add level to the given user

Xp.addLevel(<UserID - String>, <GuildID - String>, <Level - Number>)

• subtractXp — Subtract the XP from the user's current XP

Xp.addXp(<UserID - String>, <GuildID - String>, <XP - Number>)

• subtractLevel — Subtract the level from the user's current level

Xp.subtractLevel(<UserID - String>, <GuildID - String>, <Level - Number>)

• cdAppend — Add a random XP to a user every minute only (Suggested for Leveling System)

Xp.cdAppend(<UserID - String>, <GuildID - String>, <MinimumXP - Number>, <MaximumXP - Number>)

• disableGuildXp — Disable XP system to the guild if enabled

Xp.disableGuildXp(<GuildID - String>)

• disableUserXp — Disable XP system to a specific user on a guild if enabled

Xp.disableUserXp(<UserID - String>, <GuildID - String>)

• enableGuildXp — Enable XP system to the Guild if disabled

Xp.enableGuildXp(<GuildID - String>)

• enableUserXp — Enable XP system to a specific user on a guild if disabled

Xp.enableUserXp(<UserID - String>, <GuildID - String>)

Example Usage

import { Client } from "discord.js";
const client = new Client({ intents: 3276799 });
const Xp = require('@elaraa/discord-xp')

xp.connect("mongodb://...").then(() => {
  console.log("Connected to database");
});

client.on("ready", () => {
  console.log("I am ready!");
});

client.on("messageCreate", (message) => {

  const prefix = "!";
  const args = message.content.slice(prefix.length).split(/ +/);
  const command = args.shift().toLowerCase();

  if (message.author.bot || !message.content.startsWith(prefix)) return;

  xp.cdAppend(message.author.id, message.guildId, 5, 20)
    .then((msg) => {
      if (msg === "LevelUp") {
        message.channel.send({ content: "You have leveled up!" });
      }
    })
    .catch((err) => console.log("Error appending xp: " + err));

});

client.login(token);

Level Data

The current version of this package uses the XP system to determine on how much XP the user will need in order to level up. You can use the following formula to calculate how much XP you need to level up: 6 * (lvl ** 2) + (55 * lvl) + 100 - xp where lvl is your current level, and xp is how much XP you already have.

LevelXP needed to level upTotal XP required
1161161
2234468
3319957
44161664
55252625
66463876
77795453
89247392
910819729
10125012500
11143115741
12162419488
13182923777
14204628644
15227534125
16251640256
17276947073
18303454612
19331162909
20360072000
21390181921
22421492708
234539104397
244876117024
255225130625
265586145236
275959160893
286344177632
296741195489
307150214500
317571234701
328004256128
338449278817
348906302804
359375328125
369856354816
3710349382913
3810854412452
3911371443469
4011900476000
4112441510081
4212994545748
4313559583037
4414136621984
4514725662625
4615326704996
4715939749133
4816564795072
4917201842849
5017850892500
5118511944061
5219184997568
53198691053057
54205661110564
55212751170125
56219961231776
57227291295553
58234741361492
59242311429629
60250001500000
61257811572641
62265741647588
63273791724877
64281961804544
65290251886625
66298661971156
67307192058173
68315842147712
69324612239809
70333502334500
71342512431821
72351642531808
73360892634497
74370262739924
75379752848125
76389362959136
77399093072993
78408943189732
79418913309389
80429003432000
81439213557601
82449543686228
83459993817917
84470563952704
85481254090625
86492064231716
87502994376013
88514044523552
89525214674369
90536504828500
91547914985981
92559445146848
93571095311137
94582865478884
95594755650125
96606765824896
97618896003233
98631146185172
99643516370749
100656006560000