$serverLeaderboard
The function $serverLeaderboard ranks the servers (guilds) by the value of a server variable (the values written with $setServerVar / $setGuildVar) and writes the top 10 into the description of the first embed of the response. Each entry is a server, not a user. It returns an empty string.
Syntax
$serverLeaderboard[variable]
$serverLeaderboard[variable;sort]
| Parameter | Required | Description |
|---|---|---|
variable |
Yes | The name of the server variable to rank (an empty name raises A variable name is required.) |
sort |
No | desc (descending, default when omitted or empty) or asc (ascending), case-insensitive. Any other value raises Sort type must be asc or desc. |
How It Works
- The stored values of the server variable for every server that has one are read; values that are not numbers are ignored (at most the first 20000 stored values are read).
- The entries are sorted according to the specified direction and only the first 10 are kept.
- The description of the first embed (embed index 1) is replaced by one line per entry, in the format
N. server name - value(the server ID is used if the name cannot be found; integer values are printed without decimals). - The function itself returns an empty string, so its result cannot be captured with
$textSplitor inside other text: the ranking only appears in the embed description. A$descriptionplaced in the same command sets the same field, so only use one of them.
An error No message service configured. is raised if the command has no message output.
Typical Usage
Put the function next to the other embed parts (title, color…). To build your own display, read the entries one by one with $getLeaderboardValue[server;variable;sort;position].
Data Persistence
The ranked variable must be a server variable, defined with $setServerVar or $setGuildVar.
Example of updating the score of the current server:
$setServerVar[xp;$sum[$getServerVar[xp];$random[10;50]]]
Sorting
desc(default): Highest values first (XP, messages, coins).asc: Lowest values first (warns, times, penalties).
Common Use Cases
- 🏆 Server ranking: compare the servers where the bot is used, for example by a message counter stored in a server variable.
- 🎯 Events: temporary rankings of servers for contests.
Important Notes
- The entries are servers: use
$userLeaderboardto rank the members of the current server, or$globalUserLeaderboardto rank users across servers. - Servers that do not have the specified variable set are ignored, as are values that are not numbers.
- At most the first 10 entries are shown.
See Also
$getLeaderboardValue— Entry at a given position (typeserver)$globalUserLeaderboard— Ranking of global user values$userLeaderboard— Ranking of the members of the server$setServerVar— Set a server variable
Examples
Server Level Leaderboard
$title[🏆 Server Level Leaderboard]
$serverLeaderboard[level;desc]
$color[#FEE75C]
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.