Skip to main content

Shop command

this command would allow users to view available items in the shop.

  • /shop

Shop Example

Arguments

1. order
  • Description : order items by their price
  • Type : Text
  • Argument Required : False
  • Choices :
    • Ascending - asc
    • Descending - desc
2. page
  • Description : shop's page number
  • Type : Whole Number
  • Argument Required : False
  • Minimum Value : 1

Get Stored Variable

  • Variable : shop
  • Set Temporary Variable : shop

Calculate Value

  • Temporary Variable : list
Expression
let list = var('shop') ?? [];
let currency = "🪙";
let page = arg('page') != nil ? (arg('page') - 1)*5 : 0;

let shop = sortBy(list, .price, arg('order') ?? "asc")[page:page+5];

map(shop, {
let item_number = string(page + #index + 1);
[
"` " + string(item_number) + ". ` **" + toJSON(.price) + "** " + currency + " - **" + .name + "** ",
"-# - ID : `" + .id + "`",
"-# - Remaining stock : " + ( .stock != nil ? toJSON(.stock) : "unlimited"),
"-# - Required role : " + ( .require != nil ? "<@&" + .require + ">" : "none" ),
"-# - Gives you " + "<@&" + .role + "> role.",
"> -# " + .desc,
""
]
})

Create Response Message

  • Add an embed
  • Embed Title : 🛒 Shop
Embed Description
{{var('list') | map({join(#, "\n")}) | join("\n\n")}}
Embed Footer
Page {{arg('page') ?? 1}} of {{var('shop') ?? "0" | len()/5 | ceil()}} ; Total items in shop - {{var('shop') != nil ? len(var('shop')) : "0"}}

Shop Flow

tip

You can edit other parts of the embed such as image, color, etc. as you wish!