Skip to content
Variables getLeaderboardPosition

$getLeaderboardPosition

The function $getLeaderboardPosition[] returns the rank (1 for the first, 2 for the second, etc.) of a user in the ranking built from a stored variable.

Syntax

$getLeaderboardPosition[type;varName;sort;(userID)]

Parameters

Parameter Description
type Required. The scope of the variable: user (values of the members of the current server, as written by $setUserVar) or globalUser (global user values, as written by $setVar[name;value;userID]). Case-insensitive. server is refused by this function (Variable type must be user or globalUser.). 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.
userID Optional. The user whose rank is returned. If omitted or empty, the author of the command is used.

Return Value

  • Type: String (a number)
  • The rank of the user in the ranking.
  • An empty string if the user does not appear in the ranking.
  • An error is raised if the type, the variable name or the sort 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 user type, only the members of the current server are ranked.
  • It is typically paired with $getLeaderboardValue, which reads the entry at a given position.

See Also

Examples

Leaderboard Rank

$title[Leaderboard Rank 🏆]
$description[<@$authorID>, your current rank is **#$getLeaderboardPosition[user;coins;desc]**!]
$color[#FEE75C]

Rank of another user

$sendMessage[Rank of <@$mentioned[1]>: #$getLeaderboardPosition[globalUser;xp;desc;$mentioned[1]]]

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.