Lunacord

Commands

The default command pack, overrides, middleware, and registering your own.

The default pack

music.commands.installDefaults() publishes 18 slash commands:

NameDescription
/playSmart URL / provider detection, fallback chain
/pause, /resumeToggle playback
/stopStop, clear queue, leave voice
/skip, /previousSkip forward / rewind via history
/seekSeek to seconds
/volumeGet or set (0–1000)
/queue, /clear, /nowplayingQueue inspection + management
/shuffleShuffle upcoming queue
/repeattrack | queue | off
/filterPreset: bassboost, nightcore, vaporwave, karaoke, clear
/lyricsCurrent track lyrics (opt. query)
/autoplayToggle state flag — combine with createAutoplayPlugin
/join, /leaveVoice channel control

Install options

await music.commands.installDefaults({
  scope: "guild",              // or "global"
  guildId: "123...",           // required when scope: "guild"
  only: ["play", "skip"],      // install a subset
  except: ["autoplay"],        // or exclude some
  skipPublish: true,           // register handlers but skip the Discord REST PUT
});

Use scope: "guild" during development — commands appear instantly. Global commands take up to an hour to propagate.

Override a command

music.commands.override("play", async (ctx) => {
  const query = ctx.interaction.options.getString("query", true);
  return ctx.reply(`(custom play) ${query}`);
});

Add middleware (pre-handler hooks)

Middleware runs before the handler, and can short-circuit by not calling next().

music.commands.extend("skip", async (ctx, next) => {
  // gate by role
  const member = ctx.interaction.member;
  if (!member || !("permissions" in member)) {
    return ctx.error("Members only.");
  }
  return next();
});

Add your own command

import { SlashCommandBuilder } from "discord.js";

music.register({
  data: new SlashCommandBuilder().setName("ping").setDescription("Pong."),
  execute: async (ctx) => ctx.reply("Pong!"),
});

The CommandContext gives you:

  • ctx.interaction — typed ChatInputCommandInteraction
  • ctx.lunacord — the manager
  • ctx.music — the MusicKit itself
  • ctx.getPlayer() — existing player or undefined (also sets its text channel)
  • ctx.joinAndGetPlayer() — get or create + connect voice (replies with an error ephemerally if the user isn't in VC)
  • ctx.resolveVoiceChannel() — resolves the user's voice channel id
  • ctx.reply(payload) / ctx.error(message) — reply helpers

On this page