Examples
Every example here has been run with the engine. .Args are the words after the command.
A greeting
Section titled “A greeting”Hello {{ .User.Username }}, welcome to {{ .Guild.Name }}!An embed
Section titled “An embed”{{ sendMessage nil (cembed "title" "Server info" "description" (printf "**%s** has %d members." .Guild.Name .Guild.MemberCount) "color" "#8399ff" "fields" (cslice (cslice "Channel" .Channel.Mention true) (cslice "Asked by" .User.Mention true)) "footer" (print "Prefix: " .Prefix)) }}Roll a dice
Section titled “Roll a dice”!roll 20 rolls a number from 1 to 20, and !roll uses 6.
{{ $sides := 6 }}{{ if .Args }}{{ $sides = toInt (index .Args 0) }}{{ end }}{{ if lt $sides 2 }}Use a number of 2 or more.{{ return }}{{ end }}You rolled **{{ add 1 (randInt $sides) }}** (1 to {{ $sides }}).Add numbers
Section titled “Add numbers”!sum 4 5 6 answers 15.
{{ if not .Args }}Use: {{ .Prefix }}{{ .Cmd }} 1 2 3{{ return }}{{ end }}{{ $total := 0 }}{{ range .Args }}{{ $total = add $total . }}{{ end }}{{ $total }}A command only for a role
Section titled “A command only for a role”{{ if not (hasRole "223456789012345678") }}Only the staff can use this.{{ return }}{{ end }}{{ sendMessage nil "Hello, staff!" }}Give and take a role
Section titled “Give and take a role”{{ if hasRole "223456789012345678" }} {{ removeRole "223456789012345678" }}You no longer have the role.{{ else }} {{ addRole "223456789012345678" }}You now have the role.{{ end }}Choose from a list
Section titled “Choose from a list”{{ $answers := cslice "Yes" "No" "Maybe" "Ask again" }}{{ index $answers (randInt (len $answers)) }}A list with a number for each line
Section titled “A list with a number for each line”!list apples bananas cherries
{{ range $i, $item := .Args }}{{ add $i 1 }}. {{ title $item }}{{ end }}Time left until a date
Section titled “Time left until a date”{{ $target := 1893456000 }}{{ $left := sub $target (unix) }}{{ if gt $left 0 }}It ends in {{ humanizeDuration $left }} ({{ timestamp $target "R" }}).{{ else }}It already ended.{{ end }}Delete the command and answer in private
Section titled “Delete the command and answer in private”{{ deleteTrigger }}{{ sendDM (print "You used " .Prefix .Cmd " in " .Guild.Name ".") }}A counter of hugs
Section titled “A counter of hugs”{{ $total := dbIncr "hugs" 1 }}{{ .User.Mention }} gave a hug. Hugs in this server: **{{ $total }}**.A daily reward with a cooldown
Section titled “A daily reward with a cooldown”{{ if dbGet "daily" .User.ID }}You already claimed it today. Come back later.{{ return }}{{ end }}{{ dbSetExpire "daily" true 86400 .User.ID }}{{ $coins := dbIncr "coins" 100 .User.ID }}You claimed 100 coins. You have {{ $coins }}.A leaderboard
Section titled “A leaderboard”{{ range $i, $entry := dbTop "coins" 5 }}{{ add $i 1 }}. {{ mentionUser $entry.UserID }}: {{ $entry.Value }}{{ else }}Nobody has coins yet.{{ end }}A button that gives a role
Section titled “A button that gives a role”Put the ID of a role without moderation permissions. !customcommand code getrole <this code>.
{{ if eq .Trigger "command" }} {{ sendMessage nil (complexMessage "content" "Press the button to get or lose the role." "components" (cslice (crow (cbutton "label" "Toggle role" "id" "toggle" "style" "primary")))) }} {{ return }}{{ end }}{{ if hasRole "223456789012345678" }} {{ removeRole "223456789012345678" }}{{ respond "Role removed." true }}{{ else }} {{ addRole "223456789012345678" }}{{ respond "Role added." true }}{{ end }}A shop menu
Section titled “A shop menu”{{ if eq .Trigger "command" }} {{ sendMessage nil (complexMessage "components" (cslice (crow (cselect "id" "buy" "placeholder" "Buy something" "options" (cslice (cslice "Cookie (10)" "cookie") (cslice "Cake (50)" "cake")))))) }} {{ return }}{{ end }}{{ $item := index .Values 0 }}{{ $price := 10 }}{{ if eq $item "cake" }}{{ $price = 50 }}{{ end }}{{ $coins := or (dbGet "coins" .User.ID) 0 }}{{ if lt $coins $price }}{{ respond (printf "You need %d coins, you have %d." $price $coins) true }}{{ return }}{{ end }}{{ $left := dbIncr "coins" (sub 0 $price) .User.ID }}{{ respond (printf "You bought a %s! You have %d coins left." $item $left) true }}Answer when someone says a phrase
Section titled “Answer when someone says a phrase”Set it with !customcommand trigger gm exact good morning.
Good morning, {{ .User.Mention }}! ☀️