Skip to content

wc.slashCommand()

paige edited this page Aug 29, 2023 · 18 revisions
  • Description: Creates a new slash command.

Parameters

  • Name String: The name of the command (REQUIRED)
  • Description String: A description of the command (REQUIRED)
  • Cooldown String or Number: Cooldown for the command, if number it defaults to seconds. ( 10 == "10s")
  • Options Array: Options for the command
  • Action Function: What is done when the command is ran
  • NSFW Boolean: If the command is NSFW or not

Parts

  • ctx Interaction: Context of the command's interaction
  • cmd Command: Info about the command like name, arguments, cooldown, etc
{
    ctx: Interaction, // interaction for the command

    cmd: {
        name: String, // command name (required)
        description: String, // command description (required)
        options: Array, // command options
        nsfw: Boolean, // if the command is nsfw or not
        args: Array, // command arguments
        data: Function, // action the command does

        cooldown: {
            data: Set, // stores the users on cooldown
            active: Boolean, // if the cooldown is active
            time: Number, // how long the cooldown is

            relative: String, // relative unix timestamp
            raw: Number, // raw unix timestamp

            handle: Function, // handler
            fetch: Function // fetcher
        },

        onCooldown: Boolean, // if the command is on cooldown
        cooldownType: String // type of cooldown
    }
}

Options

  • Name String: Name of the option
  • Description String: Description of the option
  • Required Boolean: If the option is required or not
  • Type String or Number: Type of the option
{
    name: String,
    description: String,
    required: Boolean,
    type: String
}

Setup

wc.slashCommand("name", "description", async (ctx, cmd) => {
    // action
})

wc.slashCommand( {name: "name", description: "description"}, async (ctx, cmd) => {
    // action
})

wc.slashCommand( {name: "name", desc: "description"}, async (ctx, cmd) => {
    // action
})

wc.slashCommand( {name: "name", desc: "description", cooldown: 10}, async (ctx, cmd) => {
    // action
})

wc.slashCommand( {name: "name", desc: "description", cooldown: "10s"}, async (ctx, cmd) => {
    // action
})

Examples

!ping command

wc.slashCommand("ping", "Replies with pong!", async (ctx) => {
    ctx.reply("pong!");
});

!say command

let options = [{
    name: "Text",
    desc: "What it sends",
    type: "string",
    required: true
}]

wc.slashCommand({ name: "say", desc: "Sends what you enter", options: options}, async (ctx, cmd) => {
    ctx.channel.send(cmd.args[0].value)
});

!avatar command

wc.slashCommand("avatar", "Sends a user's avatar", async (ctx, cmd) => {
    // if there is no argument it defaults to the message author
    let user = await wc.fetchUser(cmd.args[0]);

    return ctx.reply(wc.user.avatar(user));
});

!avatar command (with cooldown)

wc.command( {name: "avatar", desc: "Sends a user's avatar", cooldown: "3s"}, async (ctx, cmd) => {
    if (cmd.onCooldown) return wc.reply("Command is on cooldown!", { ephemeral: true });
    
    // if there is no argument it defaults to the message author
    let user = await wc.fetchUser(cmd.args[0]);

    return ctx.reply(wc.user.avatar(user));
});
Clone this wiki locally