wc.command() - shysolocup/willclient GitHub Wiki
- Description: Creates a new prefix command.
Parameters
- Name
String
: The name of the command - Aliases
Array
: Array of alternate names for the command - Cooldown
String
orNumber
: Cooldown for the command, if number it defaults to seconds. ( 10 == "10s") - Action
Function
: What is done when the command is ran
Parts
- ctx
Message
: Context of the command's message - cmd
Command
: Info about the command like name, arguments, cooldown, etc
{
ctx: Message, // message for the command
cmd: {
name: String, // command name
aliases: Array, // command aliases
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
}
}
Setup
wc.command("name", async (ctx, cmd) => {
// action
})
wc.command( {name: "name"}, async (ctx, cmd) => {
// action
})
wc.command( {name: "name", aliases: ["name2", "name3"]}, async (ctx, cmd) => {
// action
})
wc.command( {name: "name", cooldown: 10}, async (ctx, cmd) => {
// action
})
wc.command( {name: "name", cooldown: "10s"}, async (ctx, cmd) => {
// action
})
Examples
!ping command
wc.command("ping", async (ctx) => {
ctx.reply("pong!");
});
!say command
wc.command("say", async (ctx, cmd) => {
console.log(cmd.args[0]); // "arguments"
console.log(cmd.args[1]); // "are"
console.log(cmd.args[cmd.args.length-1]); // "thing!"
ctx.channel.send(cmd.args.join(" ")); // sends "arguments are a thing!"
});
!avatar command
wc.command( {name: "avatar", aliases: ["av"]}, 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", aliases: ["av"], cooldown: "1s"}, async (ctx, cmd) => {
if (cmd.onCooldown) return wc.reply("Command is on cooldown!", {deleteAfter: "1s"});
// 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));
});