@pierok/commandhandler
Version:
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.
162 lines (133 loc) • 4.49 kB
Markdown
>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.
> [!WARNING]
> Some features may not work properly as the project is no longer actively maintained.
**1**. Install package:
```bash
npm install @pierok/commandhandler
yarn add @pierok/commandhandler
pnpm install @pierok/commandhandler
```
<bt></br>
**2**. In your command file, require the following:
*JavaScript:*
```js
const { Command } = require('@pierok/commandhandler');
```
*TypeScript:*
```ts
import { Command, CommandOptions, RunOptions } from '@pierok/commandhandler';
```
<bt></br>
*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<string>} 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);
```
*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<string>} 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);
```
> [!NOTE]
> If you have any bugs, please submit them [here](https://github.com/pierokchad/commandhandler/issues).
> [!NOTE]
> You can [contribute](https://github.com/pierokchad/commandhandler/tree/main/docs/CONTRIBUTING.md) if you want.