Command properties
This page assumes you have a basic bot running using NYXBCommands as seen here.
A command's file name will become the executable name of the command. Additional aliases can be set.
This code is designed for demonstration purposes only. Copy/pasting this will lead to errors.
Object properties
All commands are exported as objects who have properties to dictate the command's functionality. Here is a complete list of all current properties available to you:
Typescript
export default {
// REQUIRED
// This function will be invoked when users run this command
callback: ({
// An instance of your bot's client
client: Client,
// An instance of NYXBCommands
instance: NYXBCommands,
// The message used for legacy commands. This is null
// if the user ran this command as a slash command
message: Message,
// The interaction used for slash commands. This is null
// if the user ran this command as a legacy commands
interaction: Interaction,
// Each argument sent with this command. For legacy commands
// each word is treated as an argument
args: string[],
// All of the arguments joined together into one string
text: string,
// The guild where this command was ran
guild: Guild | null,
// The memebr who ran this command
member: Member | null,
// The user who ran this command
user: User,
// The channel where this command was ran
channel: TextChannel,
// A method run cancel a cooldown
cancelCooldown: () => {},
// A method to update a cooldown experation date
updateCooldown: (expires: Date) => {},
}) => {
// TODO: Return an object or string that will be sent in
// either message.reply or interaction.reply
// depending on how the user ran this command
},
// REQUIRED
// What type of command this is. Options:
// LEGACY
// SLASH
// BOTH
type: CommandType.BOTH,
// A method that is invoked when the command is first registered
// Perfect for pulling information from a database
init: (client: Client, instance: NYXBCommands) => {},
// REQUIRED IF THIS COMMAND IS A "SLASH" OR "BOTH" TYPE
// Sets the description for this command
description: "Add your description here",
// What other aliases should this command have as a legacy command
aliases: [],
// If this command should only be registered for test servers
testOnly: false,
// If this command should only be ran within guilds/servers
guildOnly: false,
// If this command should only be ran by bot owners/developers
// NOTE: This has nothing to do with guild/server owners
ownerOnly: false,
// What build in Discord permissions are required to use this command
permissions: [],
// If this slash command should be defered. Options:
// "ephemeral" // Creates an ephemeral reply that is deferred
// true // Creates a publicly visible reply that is deferred
// flase // Default value
deferReply: false,
// Customize how cooldowns work for this command
cooldowns: {
// Custom error message for this command
errorMessage: "Please wait {TIME}",
// You MUST select ONE of the following:
// Applies a cooldown to a specific user over all guilds and DMs
perUser: 10, // Example of 10 seconds
// Applies a cooldown to a specific user in a specific guild
perUserPerGuild: "10 s", // Example of 10 seconds
// Applies a cooldown to all users in a specific guild
perGuild: "10 h", // Example of 10 hours
global: "1 d", // Example of 1 day
},
// What the minimum amount of arguments are. Used for legacy commands
// or slash commands when you don't provide an options array
minArgs: 0,
// What the maximum amount of arguments are. Used for legacy commands
// or slash commands when you don't provide an options array.
// -1 = unlimited arguments
maxArgs: -1,
// The message to be sent if the user doesn't provide the correct syntax
correctSyntax: "Correct syntax: {PREFIX}{COMMAND} {ARGS}",
// The exact arguments the user is expecting to enter. This is used for
// the "{ARGS}" in the "correctSyntax". If you do not provide an options
// array then your slash command arguments are created using this string.
// Example for an "!add 5 10" command:
// expectedArgs: "[num1] [num2]"
// Another syntax:
expectedArgs: "<num1> <num2>",
// An array of https://discord.js.org/#/docs/discord.js/main/typedef/ApplicationCommandOption
options: [],
// This function is invoked when autocomplete is ran in this command.
// To enable autocomplete pass in an options array with "autocomplete: true"
autocomplete: (command: Command, argument: string, instance: NYXBCommands) => {
// TODO: Return an array of strings
},
// If message.reply() vs message.channel.send() should be used for
// legacy commands
reply: true,
// Delete this command as both a legacy and slash command
// This will delete the "testOnly" or "global" version of this slash
// command. For example: testOnly = true && delete = true then this slash
// command will be deleted in the test servers only. However testOnly = false
// means the global slash command will be deleted.
delete: false
} as CommandObject
CommandsPing pong command exampleNYXBCommands is easy to get setup and working. On this page you will learn how to create a simple "Ping -> Pong" command.
First you must setup NYXBCommands in your main file:CommandsCorrect argument usageYou can specify the exact arguments and the minimum/maximum number of arguments for each command. If the user provides an incorrect number of arguments then NYXBCommands will automatically tell them the correct usage based off of the command properties you provided. Here is an example: