This is a simple and unique package which makes creating commands using .js and .ts a whole lot easier and make the code look cleaner.
npm install @pierok/commandhandlerbash
npm
npm install @pierok/commandhandler
yarn
yarn add @pierok/commandhandler
pnpm
pnpm install @pierok/commandhandler
`
2. In your command file, require the following:
JavaScript:
`js
const { Command } = require('@pierok/commandhandler');
`
TypeScript:
`ts
import { Command, CommandOptions, RunOptions } from '@pierok/commandhandler';
`
$3
JavaScript:
`js
const { Command } = require('@pierok/commandhandler');
const { Client, CommandInteraction, ApplicationCommandType } = require('discord.js');
module.exports = new Command({
name: "example",
description: "An example command",
type: ApplicationCommandType.ChatInput,
/**
* @param {Object} options
* @param {Client} options.client
* @param {CommandInteraction} options.interaction
* @param {Array} options.args
*/
async run({ client, interaction, args }) {
await interaction.reply("Hello world!");
},
});
`
TypeScript:
`ts
import { Command, CommandOptions, RunOptions } from '@pierok/commandhandler';
import { Client, CommandInteraction, ApplicationCommandType } from 'discord.js';
const commandOptions: CommandOptions = {
name: "example",
description: "An example command",
type: ApplicationCommandType.ChatInput,
/**
* @param {RunOptions} options
*/
async run({ client, interaction, args }: RunOptions) {
await interaction.reply("Hello world!");
},
};
export default new Command(commandOptions);
`
$3
JavaScript:
`js
const { Command } = require('@pierok/commandhandler');
const { Client, CommandInteraction, ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js');
module.exports = new Command({
name: "subcommand",
description: "A command with subcommands",
type: ApplicationCommandType.ChatInput,
options: [
{
name: "subcommand",
description: "A subcommand",
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: "input",
description: "Input value",
type: ApplicationCommandOptionType.String,
required: true
}
]
}
],
/**
* @param {Object} options
* @param {Client} options.client
* @param {CommandInteraction} options.interaction
* @param {Array} options.args
*/
async run({ client, interaction, args }) {
await interaction.reply( Subcommand executed with args: ${args.join(', ')});
},
});
`
TypeScript:
`ts
import { Command, CommandOptions, RunOptions } from '@pierok/commandhandler';
import { Client, CommandInteraction, ApplicationCommandType, ApplicationCommandOptionType } from 'discord.js';
const commandOptions: CommandOptions = {
name: "subcommand",
description: "A command with subcommands",
type: ApplicationCommandType.ChatInput,
options: [
{
name: "subcommand",
description: "A subcommand",
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: "input",
description: "Input value",
type: ApplicationCommandOptionType.String,
required: true
}
]
}
],
/**
* @param {RunOptions} options
*/
async run({ client, interaction, args }: RunOptions) {
await interaction.reply(Subcommand executed with args: ${args.join(', ')});
},
};
export default new Command(commandOptions);
``