Skip to content
This repository has been archived by the owner on Jun 25, 2023. It is now read-only.

Commit

Permalink
Field Modifier Release
Browse files Browse the repository at this point in the history
  • Loading branch information
ming-suhi committed Aug 29, 2022
2 parents 8316237 + 084b08c commit ce9dd4d
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 290 deletions.
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


## I. About
A discord.js extension for easily structuring and managing your Discord Slash Commands. For an in-depth documentation visit the <a href="https://ming-suhi.github.io/djs-commando/" target="_blank">documentation website</a>. Or join the <a href="https://discord.com/invite/P3UMxQCEaY" target="_blank">support server</a> to talk with the developer. Please note that this package is not affiliated with discord.js.
A discord.js extension for easily building and receiving your Discord Slash Commands. For an in-depth documentation visit the <a href="https://ming-suhi.github.io/djs-commando/" target="_blank">documentation website</a>. Or join the <a href="https://discord.com/invite/P3UMxQCEaY" target="_blank">support server</a> to talk with the developer. Please note that this package is not affiliated with discord.js.

## II. Quick Start

Expand All @@ -25,63 +25,64 @@ npm install @ming-suhi/djs-commando
```

## B. Creating a Command
Start creating a command by making a file inside a designated folder. File name doesn't need to be command name. Require the needed command class from `@ming-suhi/djs-commando`. Command classes include
`Command`, `Subcommand`, `SubcommandGroup`, `UserCommand` and `MessageCommand`. To create a command class make a new instance of the chosen class and set its properties. Finally for command to be handled by the package, export it with `module.exports`. `module.exports` only top commands(Command, UserCommand, MessageCommand) not command options such as Subcommand and SubcommandGroup(command options will be discussed below).

To create a command, start by making a file inside a designated folder. Require/import the needed command class from `@ming-suhi/djs-commando`. Top level command classes include `SlashCommand`, `MessageCommand`, and `UserCommand`. To create a command, extend the chosen class and set its name and description in the constructor(`MessageCommand` and `UserCommand` doesn't have a description). Add an execute method with one parameter of Interaction type. This method will run if the command is called by a user from Discord. Finally, for command to be handled by the package, export it with `module.exports`.
```js
const { Command } = require('@ming-suhi/djs-commando');
const { SlashCommand } = require('@ming-suhi/djs-commando');

const command = new class extends Command {
const command = new class extends SlashCommand {
constructor() {
super();
this.name = "ping";
this.description = "get ponged";
}

async execute(interaction) {
interaction.reply("pong");
await interaction.reply("pong");
}
}

module.exports = command;
```

## C. Adding Command Options

Require the needed command class from `@ming-suhi/djs-commando`. Command options include `Subcommand`,
`SubcommandGroup`, `StringField`, `IntegerField`, `BooleanField`, `UserField`, `ChannelField`, `RoleField`,
`MentionableField`, `NumberField`, and `AttachmentField`. Create a new instance of the chosen class and pass it inside an array as an argument to it's parent's constructor.
A SlashCommand can take on options which includes subcommands, subcommand groups and fields. To create a subcommand, import `Subcommand` from `@ming-suhi/djs-commando`, and create a new class extending `Subcommand` and set its name and description in the constructor. To attach the subcommand to a SlashCommand or subcommand group pass it inside super. Creating a subcommand group is similar to creating a subcommand. Available fields are `StringField`, `IntegerField`, `BooleanField`, `UserField`, `ChannelField`, `RoleField`, `MentionableField`, `NumberField`, and `AttachmentField`. To create a field, create a new instance of the chosen field class which takes on 3 arguments: a name and description and a boolean that states if the field is required. Attach it to a Slashcommand or Subcommand inside super.

```js
const { StringField } = require('@ming-suhi/djs-commando');
const { SlashCommand, Subcommand, StringField } = require('@ming-suhi/djs-commando');

// Creation of field differs from subcommand and subcommand group
// Subcommand and subcommand group are created like Command, UserCommand and MessageCommand
const message = new StringField('message', 'message to echo', true);

const command = new class extends Command {
const subcommand = new class extends Subcommand {
constructor() {
super([message]); // pass all options inside an array
this.name = "echo";
this.description = "echo a message";
super([message]);
this.name = "message";
this.description = "echos a message";
}

async execute(interaction) {
interaction.reply("pong");
const messageArg = interaction.options.getString("message");
await interaction.reply(messageArg);
}
}

module.exports = command; // only export top command
const command = new class extends SlashCommand {
constructor() {
super([subcommand]);
this.name = "echo";
this.description = "echo commands";
}
}

module.exports = command; // Only export top command
```

## D. Register Commands
## D. Registering Commands
Before receiving commands, load all commands. First, require `InteractionsHandler` from `@ming-suhi/djs-commando`. Create new instance of `InteractionsHandler` and call `loadCommands` method. The method requires one argument which is the path to the commands folder.
```js
const { InteractionsHandler } = require('@ming-suhi/djs-commando');

const handler = new InteractionsHandler();
handler.loadCommands("ABSOLUTE/PATH/TO/COMMANDS/FOLDER");

```

## E. Receiving Commands
Expand Down
Loading

0 comments on commit ce9dd4d

Please sign in to comment.