Skip to main content

View Leaderboard

This command displays a paginated leaderboard where users with higher experience come first.

Trigger

Type: Regex
Trigger: \A(-|<@!?204255221017214977>\s*)(leaderboard|lb|top)(\s+|\z)

Usage

  • -leaderboard - Views the first page of the leaderboard.
  • -leaderboard <page> - Views a specific page of the leaderboard.
Aliases

Instead of using leaderboard, you can also use lb or top.

Code

{{/*
Views the leaderboard of the server for the leveling system.
See <https://yagpdb-cc.github.io/leveling/view-leaderboard> for more information.

Author: jo3-l <https://github.com/jo3-l>
*/}}

{{ $page := 1 }}
{{ with reFind `\d+` (joinStr " " .CmdArgs) }} {{ $page = . | toInt }} {{ end }}
{{ $skip := mult (sub $page 1) 10 }}
{{ $users := dbTopEntries "xp" 10 $skip }}
{{ if not (len $users) }}
There were no users on that page!
{{ else }}
{{ $rank := $skip }}
{{ $display := "" }}
{{ range $users }}
{{- $usr := .User.String }}
{{- if eq $usr "#" }}
{{- $usr = .UserID }}
{{- end }}
{{- $xp := toInt .Value }}
{{- $rank = add $rank 1 }}
{{- $display = printf "%s\n• **%d.** [%s](https://yagpdb.xyz) :: Level %d (%d XP)"
$display $rank $usr (toInt (roundFloor (mult 0.1 (sqrt $xp)))) $xp -}}
{{ end }}
{{ $id := sendMessageRetID nil (cembed
"title" "❯ Leaderboard"
"thumbnail" (sdict "url" "https://i.imgur.com/mJ7zu6k.png")
"color" 14232643
"description" $display
"footer" (sdict "text" (joinStr "" "Page " $page))
) }}
{{ addMessageReactions nil $id "◀️" "▶️" }}
{{ end }}

Author

This custom command was written by @jo3-l.