Skip to content

wc.slashCommand()

paige edited this page Aug 30, 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 || Number
}
Types Alternates Bits
sub_command • sub_com
• sub
1
sub_command_group • sub_com_group
• sub_group
2
string • str 3
integer • int 4
booelan • bool 5
user • member 6
channel None 7
roles None 8
mentionable • mention 9
number • num 10
attachment • file 11

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, cmd) => {
    ctx.reply("Pong!");
});

!say command

async function action(ctx, cmd) {
	ctx.channel.send(cmd.args[0].value)

	wc.reply(`Well said!`, { ephemeral: true })
};

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

wc.slashCommand({ name: "say", desc: "Sends what you enter", options: options}, action);

!avatar command

async function action(ctx, cmd) {
	let user = (cmd.args[0]) ? await wc.fetchUser(cmd.args[0].value) : ctx.user

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

let options = [
	{
		name: "user",
		description: "user to get",
		type: "user"
	}
];

wc.slashCommand({ name: "avatar", desc: "Sends a user's avatar", options: options}, action);

!avatar command (with cooldown)

async function action(ctx, cmd) {
	if (cmd.onCooldown) return wc.reply("Command is on cooldown!", { ephemeral: true });

	let user = (cmd.args[0]) ? await wc.fetchUser(cmd.args[0].value) : ctx.user

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

let options = [
	{
		name: "user",
		description: "user to get",
		type: "user"
	}
];

wc.slashCommand({ name: "avatar", desc: "Sends a user's avatar", options: options, cooldown: "5s"}, action);
Clone this wiki locally