@pierok/commandhandler
v2.0.0
Published
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.
Downloads
17
Maintainers
Keywords
Readme
✨ Discord.js v14 command framework
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.
🚀 Installation
1. Install package:
# npm
npm install @pierok/commandhandler
# yarn
yarn add @pierok/commandhandler
# pnpm
pnpm install @pierok/commandhandler
2. In your command file, require the following:
JavaScript:
const { Command } = require('@pierok/commandhandler');
TypeScript:
import { Command, CommandOptions, RunOptions } from '@pierok/commandhandler';
📑 Code example - command format
JavaScript:
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<string>} options.args
*/
async run({ client, interaction, args }) {
await interaction.reply("Hello world!");
},
});
TypeScript:
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);
📑 Code example - subcommand format
JavaScript:
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<string>} options.args
*/
async run({ client, interaction, args }) {
await interaction.reply(`Subcommand executed with args: ${args.join(', ')}`);
},
});
TypeScript:
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);
🔧 Bugs
If you have any bugs, please submit them here.
🎲 Contributions
You can contribute if you want.