aoijs-command-manager-v2
Version:
A command manager for aoi.js that handles slash commands with ease.
132 lines (99 loc) ⢠3.43 kB
Markdown
A command manager for aoi.js that handles slash commands with ease.
- š Automatic command synchronization with Discord API
- š easy way to create, edit a slash command
- ā
Command validation and error checking
```bash
npm install aoi-command-manager-v2
```
```javascript
const { AoiClient } = require('aoi.js')
const { ApplicationCommandManager } = require('aoi-command-manager-v2')
const bot = new AoiClient({
token: "YOUR TOKEN",
prefix: "!",
intents: ["MessageContent", "Guilds", "GuildMessages"],
events: ["onMessage", "onInteractionCreate"],
database: {
type: "aoi.db",
db: require("@aoijs/aoi.db"),
dbType: "KeyValue",
tables: ["main"],
securityKey: "a-32-characters-long-string-here"
}
});
// Initialize the command manager
new ApplicationCommandManager(bot, {
path: './slashcommads', // Path to your commands directory
showTable: true, // Show command table (default: true)
validateCommands: true, // Validate commands (default: true)
checkUpdates: true // Check for updates (default: true)
})
client.loadCommands("./commands")
```
Examples:
```javascript
module.exports = {
name: 'ping',
type: 'slash',
prototype: "interaction",
code: `$interactionReply[My ping is $pingms]`
}
```
```javascript
const { SlashCommandBuilder } = require('discord.js')
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription("shows the bot's ping")
}
```
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| path | string |-| Path to commands directory |
| showTable | boolean | true | Show command table after loading |
| validateCommands | boolean | true | Validate commands before loading |
| checkUpdates | boolean | true | Check for package updates |
Syncs commands with Discord API.
```javascript
$applicationCommandSync[guildId1,guildId2] // Optional guild IDs
```
Reloads all commands from the directory.
```javascript
$applicationCommandReload
```
Validates all slash commands and displays any errors found.
```javascript
$applicationCommandValidate
```
Example output:
```
Slash Command Validation Errors:
ā ping: Missing description
ā help: Name must be between 1 and 32 characters
ā settings: Option 'channel' missing description
```
The command table shows the status of each loaded command. If any errors are found, it will suggest running the validation function for detailed information.
```
Loaded Slash Commands
āāāāāāāāāāā¬āāāāāāāāā¬āāāāāāāā
ā Name ā Status ā Error ā
āāāāāāāāāāā¼āāāāāāāāā¼āāāāāāāā¤
ā ping ā ā
ā ā
ā help ā ā ā Missing description ā
āāāāāāāāāāā“āāāāāāāāā“āāāāāāāā
ā ļø Some commands have errors. Run $applicationCommandValidate to see detailed validation results.
```
MIT