Command Properties

The command class has many different properties that can help you get the most out of this handlers capabilities and to allow your bot to find and execute all the commands you create. We will also be
JavaScript
TypeScript
JavaScript
// ./commands/Ping.js
const { Command, Validator } = require("cdcommands");
module.exports = new Command({
// The commands main name. Used to find the command. (type: string)
name: "ping",
// An array of command aliases that can also be used to find and
// execute the command. (type: Array<string>)
aliases: ["pong"],
// The category the command fits into. This is used to sort commands
// for the help menu. (type: string)
category: "general",
// A short description of the command that is used in help menus
// (type: string)
description: "Gets the bots connection latency",
// A more detailed description of what the command does, also is
// used in help menus. (type: string)
details: "View the bots current websocket and message latency",
// The minimum number of arguments the command expects (type: number)
minArgs: 0,
// The maximum number of arguments the command expects (type: number)
// Tip: Use Infinity for no maximum
maxArgs: Infinity,
// The expected usage of the command. Has no functionality other than
// being displayed in the help menu. (type: string)
// Tip: Use {prefix} to display the current guild prefix
usage: "{prefix}ping",
// Whether or not the command can be used only in a guild or not.
// (type: boolean)
guildOnly: false,
// Whether or not the command can only be used in direct messages.
// (type: boolean)
// Tip: Set both guildOnly and dmOnly to true to "disable" a command.
dmOnly: false,
// Whether or not the command is NSFW, and can only be used in such
// channels (type: boolean)
nsfw: false,
// Whether or not the command can only be used by the developers
// specified in the "dev" array. (type: boolean)
devOnly: false,
// Whether or not the command can be disabled by the default disable
// command (type: boolean)
noDisable: false,
// The amount of time until the same user can use said command again
// (in milliseconds), use "globalCooldown" for a cross-server
// global affect. (type: number)
// Note: Both "cooldown" and "globalCooldown" are measured in ms
cooldown: 500,
// The amount of time until anyone can use said command again
// (in milliseconds), use "cooldown" for a non-cross-server local
// affect. (type: number)
// Tip: Use 0 on either "cooldown" or "globalCooldown" for no cooldown
globalCooldown: 0,
// An array of permissions that the member will need to be able to run
// the command. Isn't used if "dmOnly" is true.
// (type: Array<PermissionResolvable>)
userPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
// An array of permissions that the bot will need to be able to run
// the command. Isn't used if "dmOnly" is true.
// (type: Array<PermissionResolvable>)
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
// More information will be provided below. (type: Validator)
validate: new Validator(),
/* (type: (client: CDClient) => Promise<unknown> | unknown)
The init method will run one time once the command is loaded.
This can be used for many different things, maybe fetching some data
from an API, or making sure some global variable is setup correctly.
Whatever it may be, it runs once on start up.
*/
init(client) {
console.log(`${client.user.username} from command ${this.name}.`);
},
// The function that you want run when the command is used.
// 5 different parameters are passed along for you to use.
// message, args, client, prefix, and language
/* (type: ({ message, args, client, prefix, language }:
{ message: Message, args: string[], client: CDClient, prefix: string, language: string }) => Promise<unknown>) */
run: ({ message, args, client, prefix, language }) => {
return message.channel.send(`My latency is **${client.ws.ping}ms**!`);
},
});
TypeScript
// ./commands/Ping.ts
import { Command, Validator } from "cdcommands";
export default new Command({
// The commands main name. Used to find the command. (type: string)
name: "ping",
// An array of command aliases that can also be used to find and
// execute the command. (type: Array<string>)
aliases: ["pong"],
// The category the command fits into. This is used to sort commands
// for the help menu. (type: string)
category: "general",
// A short description of the command that is used in help menus
// (type: string)
description: "Gets the bots connection latency",
// A more detailed description of what the command does, also is
// used in help menus. (type: string)
details: "View the bots current websocket and message latency",
// The minimum number of arguments the command expects (type: number)
minArgs: 0,
// The maximum number of arguments the command expects (type: number)
// Tip: Use Infinity for no maximum
maxArgs: Infinity,
// The expected usage of the command. Has no functionality other than
// being displayed in the help menu. (type: string)
// Tip: Use {prefix} to display the current guild prefix
usage: "{prefix}ping",
// Whether or not the command can be used only in a guild or not.
// (type: boolean)
guildOnly: false,
// Whether or not the command can only be used in direct messages.
// (type: boolean)
// Tip: Set both guildOnly and dmOnly to true to "disable" a command.
dmOnly: false,
// Whether or not the command is NSFW, and can only be used in such
// channels (type: boolean)
nsfw: false,
// Whether or not the command can only be used by the developers
// specified in the "dev" array. (type: boolean)
devOnly: false,
// Whether or not the command can be disabled by the default disable
// command (type: boolean)
noDisable: false,
// The amount of time until the same user can use said command again
// (in milliseconds), use "globalCooldown" for a cross-server
// global affect. (type: number)
// Note: Both "cooldown" and "globalCooldown" are measured in ms
cooldown: 500,
// The amount of time until anyone can use said command again
// (in milliseconds), use "cooldown" for a non-cross-server local
// affect. (type: number)
// Tip: Use 0 on either "cooldown" or "globalCooldown" for no cooldown
globalCooldown: 0,
// An array of permissions that the member will need to be able to run
// the command. Isn't used if "dmOnly" is true.
// (type: Array<PermissionResolvable>)
userPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
// An array of permissions that the bot will need to be able to run
// the command. Isn't used if "dmOnly" is true.
// (type: Array<PermissionResolvable>)
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
// More information will be provided below. (type: Validator)
validate: new Validator(),
/* (type: (client: CDClient) => Promise<unknown> | unknown)
The init method will run one time once the command is loaded.
This can be used for many different things, maybe fetching some data
from an API, or making sure some global variable is setup correctly.
Whatever it may be, it runs once on start up.
*/
init(client) {
console.log(`${client.user.username} from command ${this.name}.`);
},
// The function that you want run when the command is used.
// 5 different parameters are passed along for you to use.
// message, args, client, prefix, and language
/* (type: ({ message, args, client, prefix, language }:
{ message: Message, args: string[], client: CDClient, prefix: string, language: string }) => Promise<unknown>) */
run: ({ message, args, client, prefix, language }) => {
return message.channel.send(`My latency is **${client.ws.ping}ms**!`);
},
});

The above command, when run using either ?ping or ?pong, should have the bot respond with some message along the lines of:

My latency is 58ms!