# Leveling Manager

## RoleManager (todo)

## LevelingAccount

#### **class discordSuperUtils.Leveling.**&#x4C;evelingAccoun&#x74;**(**&#x64;atabase, table, guild: int, member: int, rank\_multiplier=1.&#x35;**)**

Initializer of LevelingAccount, represents a leveling account.

| [**Attributes**](https://discord-super-utils.gitbook.io/discord-super-utils/base#attributes) | [**Methods**](https://discord-super-utils.gitbook.io/discord-super-utils/base#methods) |
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| **`database`**                                                                               | **`xp`**                                                                               |
| **`table`**                                                                                  | **`level`**                                                                            |
| **`guild`**                                                                                  | **`next_level`**                                                                       |
| **`member`**                                                                                 | **`percentage_next_level`**                                                            |
| **`rank_multiplier`**                                                                        | **`initial_rank_xp`**                                                                  |
|                                                                                              | **`set_xp`**                                                                           |
|                                                                                              | **`set_level`**                                                                        |
|                                                                                              | **`set_next_level`**                                                                   |

### **Attributes**

* **`database` (DatabaseManager)**

  * The database of the member.

* **`table` (str)**

  * The table of the database.

* **`guild` (int)**

  * The guild id of the guild.

* **`member` (discord.Member)**

  * The member id of the member.

* **`rank_multiplier` (float)**
  * The rank multiplier of the xp.
  * Not supposed to be used by the user.

### Methods

* **`xp()`**\
  Returns the xp, this function is a coroutine.<br>

* **`level()`**\
  Returns the level of the member, this function is a coroutine.

* **`next_level()`**\
  Returns the xp until next level of the member, this function is a coroutine.

* **`percentage_next_level()`**\
  Returns the percentage until level up of the member, this function is a coroutine.<br>

* **`initial_rank_xp()`**

  Returns the initial rank xp of the member's current level, this function is a coroutine\
  Not meant to be used by the user.<br>

* **`set_xp(value)`**

  Sets the xp of the member to value, this function is a coroutine.<br>

* **`set_level(value)`**

  Sets the level of the member to value, this function is a coroutine.<br>

* **`set_next_level(value)`**

  Sets the xp until next level to value, this function is a coroutine.

## LevelingManager

#### **class discordSuperUtils.LevelingManager(**&#x62;ot, role\_manager=None, xp\_on\_message=5, rank\_multiplier=1.5, xp\_cooldown=6&#x30;**)**

Initializer of [**`LevelingManager`**](#levelingmanager), represents a leveling manager that manages the ranking system for the bot. Inherits DatabaseChecker.

{% hint style="warning" %}
All inherited methods and attributes from[ ](https://discord-super-utils.gitbook.io/discord-super-utils/base#eventmanager)DatabaseChecker are unlisted.
{% endhint %}

| [**Attributes**](#attributes) | [**Methods**](#methods) | [**Events**](#events) |
| ----------------------------- | ----------------------- | --------------------- |
| **`xp_cooldown`**             | **`generate_checks`**   | **`on_level_up`**     |
| **`role_manager`**            | **`create_account`**    |                       |
| **`bot`**                     | **`get_account`**       |                       |
| **`xp_on_message`**           | **`get_leaderboard`**   |                       |
| **`rank_multiplier`**         |                         |                       |
| **`cooldown_members`**        |                         |                       |

### **Attributes**

* **`bot` (commands.Bot)**

  * The bot the leveling manager will work on.&#x20;
  * Passed in initializer.

* **`xp_on_message`(float)**

  * XP granted on each new message, cooldown of 10 seconds between messages.
  * Passed in initializer.
  * Defaults to 5.

* **`xp_cooldown` (float)**
  * The cooldown in seconds between messages.

* **`rank_multiplier` (float)**

  * The multiplier of XP needed to level up on each level up.&#x20;
  * Passed in initializer.&#x20;
  * Defaults to 1.5.

* **`cooldown_members` (Dict\[str, Dict\[int, str]])**
  * The XP cooldown data necessary for members.

### Methods

**`get_account(member) -> LevelingAccount`**\
Gets a **member**'s XP **account**.\
Returns `None` if **account** is not found.

This functions is a coroutine \
\
**Parameters**

* **`member` (discord.Member)**

  * &#x20;Member to get account from.

**`generate_checks(member) -> Dict[str, Any]`**\
Generates database checks for the member\
\
**Parameters**

* **`member` (discord.Member)**
  * &#x20;The member to generate checks to.

**`get_leaderboard(guild) -> List[LevelingAccount]`**\
Returns the leaderboard of the guild.

This function is a coroutine\
\
**Parameters**

* **`guild` (discord.Guild)**
  * &#x20;The guild of the leaderboard.<br>

**`create_account(member)`**\
Creates an account for the member.

This function is a coroutine\
\
**Parameters**

* **`member` (discord.Member)**
  * &#x20;Member to create an account for.

### **Events**

* **`on_level_up(message, member, roles)`**\
  This event is called when a **member levels up**.\
  \
  **Parameters**
  * **`message` (discord.Message)**
    * The message the member leveled up from.
  * **`member` (LevelingAccount)**
    * The member's XP data.
  * **`roles` (List\[discord.Roles])**
    * The roles given to the member on level-up.
