Variables
getLeaderboardValue
$getLeaderboardValue
The function $getLeaderboardValue[] returns the entry found at a given position of the ranking built from a stored variable.
Syntax
$getLeaderboardValue[type;varName;sort;position;(returnType)]
Parameters
| Parameter | Description |
|---|---|
type |
Required. The scope of the variable: user (values of the members of the current server, as written by $setUserVar), globalUser (global user values, as written by $setVar[name;value;userID]) or server (values of server variables, ranked per server). Case-insensitive; any other value raises Variable type must be user, globalUser or server. In a bot that still uses the legacy user-variable behavior, user ranks the global user values like globalUser. |
varName |
Required. The name of the variable used for the ranking (an empty name raises A variable name is required.). |
sort |
Required. desc (highest value first) or asc (lowest value first), case-insensitive. Anything else, including an empty value, raises Sort type must be asc or desc. |
position |
Required. The rank to read (integer of 1 or more, otherwise the error Position must be a positive integer. is raised). |
returnType |
Optional. id (the ID of the entry), value (its value) or none (name and value). Case-insensitive; empty or omitted means none. Any other value raises Return type must be id, value or none. |
Return Value
- Type: String
- With
none(default):Name - value, where the name is the username (or the server name for theservertype), or the ID if the name cannot be found. A value without decimals is printed as an integer (7, not7.0). - With
id: the ID of the user or server at this position. - With
value: the value of the variable at this position. - An empty string if the position is beyond the end of the ranking.
- An error is raised if the type, the variable name, the sort, the position or the return type is invalid.
Behavior
- The ranking is built from the persisted values of the variable; entries whose value is not a number are ignored. At most the first 20000 stored values are read.
- With the
usertype, only the members of the current server are ranked. - It is typically paired with
$getLeaderboardPosition, which gives the rank of a user.
See Also
$getLeaderboardPosition— Get the rank of a user$globalUserLeaderboard— Top 10 of global user values$serverLeaderboard— Top 10 of servers$userLeaderboard— Top 10 of the members of the server
Examples
Best player
$title[Leaderboard Score]
$description[First place: **$getLeaderboardValue[user;coins;desc;1]**]
$color[#57F287]
Score of the third place
$sendMessage[Score of the 3rd: $getLeaderboardValue[user;coins;desc;3;value]]
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.