Najova

DocsExtensionsdiscord.najova

discord.najova/xp0.0.2

Official Najova Package

Levels from chatting: XP per message, level-up messages, role rewards and /rank.

xp: XP and levels

Needs discord.najova 0.0.7 or newer.

Switch it on for your project on the Packages page in Najova IDE (Home > Packages). Set the XP per message, level-up channel, role rewards (5:Regular, 10:Veteran) and /rank there. Then $use[discord] alone gives:

$use[discord]
$slash[me;Your XP]
  $reply[$xpOf XP, level $level]
$endslash
$prefix[boost]
  $giveXp[500]
$endprefix
$start[$env[DISCORD_TOKEN]]
FunctionGives
$xpOf or $xpOf[person]the XP of the person of the command (or the member whose id is given)
$level or $level[person]their level
$xpStats or $xpStats[person]a table: xp, level, into (XP into this level), need (XP this level takes)
$giveXp[amount] or $giveXp[amount;person]gives XP (below 0 takes it), with level-ups; the new level
$levelReward[level;role]a role members get at a level, besides the ones on the Packages page

The older way ($call)

Bots made before 0.0.7 keep working:

People get XP for chatting and go up levels. Add it to a bot with one line:

$use[discord]
$use[discord/xp]
$call[xp.reward;5;Regular]
$call[xp.rankCommand]
$call[discord.start;$env[DISCORD_TOKEN]]
  • XP: each message that is not a command gives 15 to 25 XP, at most once a minute per person.
  • Levels: level L takes 5 L² + 50 L + 100 XP to finish (100 for level 0 to 1, 155 for 1 to 2, ...).
  • Level-up message in the channel where it happened, or in one channel you pick.

Calls

CallWhat it does
$call[xp.setup;$table[min;15;max;25;wait;60;announce;yes;channel;""]]XP a message gives (min to max), seconds between counted messages, announce yes/no, a channel id for level-up messages ("" = where it happened)
$call[xp.reward;level;role]Gives the role (by name) when someone reaches the level
$call[xp.rankCommand]Adds /rank (your level, or another member's)
$call[xp.stats;where;person]A table: xp (all of it), level, into (XP into this level), need (XP this level takes). person is an id; leave it out for the person of the event
$call[xp.give;where;amount;person]Gives XP (below 0 takes it away), with level-ups; gives the new level
$call[xp.need;level], $call[xp.levelOf;xp]The level maths

XP is kept per member (each server on its own) in the member variables xp and xpAt, in discord-variables.json. The bot needs the Manage Roles permission, and its role above the reward roles, to give them.

Needs discord.najova 0.0.2 or newer.

Functions

xp.setup

$call[xp.setup;$table[min;15;max;25;wait;60;announce;yes;channel;""]]

How much XP a message gives (min, max), seconds between counted messages (wait), and the level-up message (announce, channel).

xp.reward

$call[xp.reward;5;Regular]

A role (by its name) that members get at a level.

xp.need

$call[xp.need;level]

The XP a level takes to finish (5 L² + 50 L + 100).

xp.levelOf

$call[xp.levelOf;total]

The level of a total XP.

xp.stats

$call[xp.stats;where;person]

A table about a member: xp, level, into (XP into this level) and need (XP this level takes).

xp.give

$call[xp.give;where;amount;person]

Gives XP (or takes it, below 0), with level-ups.

xp.rankCommand

$call[xp.rankCommand]

Adds /rank (yours, or another member's).

xp.xpOf

$xpOf or $xpOf[person]

The XP of the person of the command or event (or the member whose id is given).

xp.level

$level or $level[person]

The level of the person of the command or event (or the member whose id is given).

xp.xpStats

$xpStats or $xpStats[person]

A table about a member: xp, level, into (XP into this level) and need (XP this level takes).

xp.giveXp

$giveXp[50] or $giveXp[50;person]

Gives XP to the person of the command or event (or the member whose id is given); below 0 takes it away. Gives the new level.

xp.levelReward

$levelReward[5;Regular]

A role (by its name) members get at a level, besides the ones on the Packages page.