Examples

Commands

Create and organize slash commands with glyria.js.

Basic Command

Create a file inside src/commands/ — it will be automatically loaded and registered on Discord.

// src/commands/ping.ts
export default GlyriaCommand()
  .setName("ping")
  .setDescription("Pong!")
  .execute(async (ctx) => {
    await ctx.reply({ content: "Pong!" })
  })
GlyriaCommand is available globally — no import needed. \

Command with Options

// src/commands/hello.ts
export default GlyriaCommand()
  .setName("hello")
  .setDescription("Say hello to someone")
  .addUserOption((option) =>
    option
      .setName("user")
      .setDescription("The user to greet")
      .setRequired(true)
  )
  .addStringOption((option) =>
    option
      .setName("message")
      .setDescription("A custom message")
      .setRequired(false)
  )
  .execute(async (ctx) => {
    await ctx.reply({ content: "Hello!" })
  })

Available Option Types

MethodDiscord Type
addStringOptionString
addIntegerOptionInteger
addNumberOptionNumber
addBooleanOptionBoolean
addUserOptionUser
addRoleOptionRole

Permissions

Restrict a command to members with specific Discord permissions using .setPermissions():

export default GlyriaCommand()
  .setName("ban")
  .setDescription("Ban a user")
  .setPermissions(djs.PermissionsBitField.Flags.BanMembers)
  .addUserOption((option) =>
    option
      .setName("user")
      .setDescription("User to ban")
      .setRequired(true)
  )
  .execute(async (ctx) => {
    // only members with the BanMembers permission can use this command
  })

PermissionsBitField is available through the djs namespace — no import needed. ::

Metadata

Attach custom data to a command with .setMetaData(). Glyria stores this data as-is and never interprets it.

export default GlyriaCommand()
  .setName("ban")
  .setDescription("Ban a user")
  .setMetaData({
    category: "moderation",
    cooldown: 5000,
    premium: false,
    guildOnly: true,
  })
  .execute(async (ctx) => {
    // your logic here
  })

useCommands()

useCommands() returns the full list of loaded commands along with their metadata.

const commands = useCommands()

// [
//   {
//     name: "ban",
//     description: "Ban a user",
//     meta: {
//       category: "moderation",
//       cooldown: 5000
//     }
//   }
// ]

Example of a /help command organized by category:

export default GlyriaCommand()
  .setName("help")
  .setDescription("List all commands")
  .execute(async () => {
    const commands = useCommands()

    const byCategory = commands.reduce((acc, cmd) => {
      const category = (cmd.meta.category as string) ?? "general"

      acc[category] ??= []
      acc[category].push(cmd)

      return acc
    }, {} as Record<string, typeof commands>)

    // build your embed from byCategory
  })

Subcommands

// src/commands/moderation.ts
export default GlyriaCommand()
  .setName("moderation")
  .setDescription("Moderation commands")
  .addSubCommand((cmd) =>
    cmd
      .setName("ban")
      .setDescription("Ban a user")
      .addUserOption((option) =>
        option
          .setName("user")
          .setDescription("User to ban")
          .setRequired(true)
      )
      .addStringOption((option) =>
        option
          .setName("reason")
          .setDescription("Reason for the ban")
      )
      .execute(async (ctx) => {
        // handle ban
      })
  )
  .addSubCommand((cmd) =>
    cmd
      .setName("kick")
      .setDescription("Kick a user")
      .addUserOption((option) =>
        option
          .setName("user")
          .setDescription("User to kick")
          .setRequired(true)
      )
      .execute(async (ctx) => {
        // handle kick
      })
  )

Subcommand Groups

export default GlyriaCommand()
  .setName("config")
  .setDescription("Configuration commands")
  .addSubCommandGroup((group) =>
    group
      .setName("logs")
      .setDescription("Logs configuration")
      .addSubCommand((cmd) =>
        cmd
          .setName("enable")
          .setDescription("Enable logs")
          .execute(async (ctx) => {
            // handle log enabling
          })
      )
      .addSubCommand((cmd) =>
        cmd
          .setName("disable")
          .setDescription("Disable logs")
          .execute(async (ctx) => {
            // handle log disabling
          })
      )
  )

This generates a command structure similar to:

/config logs enable
/config logs disable
/moderation ban <user> [reason]
/moderation kick <user>

Organizing Commands

Subfolders inside src/commands/ are for organization only — every file, regardless of depth, is loaded automatically.

src/commands/
  ping.ts
  moderation/
    ban.ts
    kick.ts
  config/
    advanced/
      logs.ts

Keep one command per file. Use subcommands and subcommand groups to organize related functionality. :: ::

Copyright © 2026