DiamondHandler is a discord.js handler
- Features
- Instalation
- Ussage
- Documentation
- You don't have to worry about writing command handler and feature handler
- DiamondHandler has build-in language manager
- Slash Commands arugemnts parser
npm i diamond-handler
📂src
┣ 📂cmds - commands dir
┃ ┗ 📂utils - category dir
┃ ┃ ┣ 📜!category.json - category info
┃ ┃ ┗ 📜test.cmd.js - command
┣ 📂features - features dir
┃ ┗ 📜test.feature.js - feature
┣ 📜index.js - main file
┗ 📜Messages.json - JSON file for messages
const DiamondHandler = require('diamond-handler');
const { Client } = require('discord.js');
const client = new Client({
intents: [], //Your intents
});
const handler = new DiamondHandler(client, {
commandsDir: 'cmds', //Where command files are stored
featuresDir: 'features', //Where features files are stored
messagesPath: 'messages.json', //Where messages are stored
});
client.login('superSecretToken');
module.exports = {
name: 'test', //The name of the command
description: 'Test command', //The description of the command (you can also specify the description for different languages in Messages.json)
run: (interaction, args) => {
//Function parameters: 1 - interaction 2 - arguments 3- instance (DiamondHandler)
interaction.reply('Hello world!');
},
};
module.exports = (client, instance) => {
//Function parameters 1 - client 2 - instance (DiamondHandler)
console.log('Hello world!');
};
The name of the command
The description of the command
Sould the command be disabled or not
The permissions that the user must have to execute the command. If user doesn't have any of given permissions he will not be able to execute the command. If he has any of the given permissions he will be able to execute the command.
Type: Array of FLAGS or our permissions
The permissions that the bot must have to execute the command.
Type: Array of FLAGS
Command arguments
The name of the option
The description of the option
The type of the option (see option types)
Function that will be run when command is executed
Arguments provided by user
DiamondHandler instance
module.exports = {
name: 'name',
description: 'description',
options: [
{
name: 'test',
description: 'test subcommand',
type: 'sub_command',
},
{
name: 'test2',
description: 'test subcommand 2',
type: 'sub_command',
},
],
run: (interaction, args, instance) => {
console.log(args.subcommand); //'test' or 'test2'
//args.subcommand returns which subcommand was run
},
};
These are all options you can pass to the handler as second argument
Directory where commands are stored
Directory where features are stored
File where messages are stored
If file in commandsDir or featuresDir not ends with this this file will be ignored
File endings in commandsDir. Default: .cmd.js
File endings in featuresDir. Default: .feature.js
Default language used in message system. Default: english
Sets the default color in embed
The color to set
Sets guild language (used in message system)
ID of the guild to be set on
Language to set
Sets guild permissions (used in permission system)
ID of the guild to set on
Permissions to set
Similar to setGuildPermissions
but sets global permissions (permissions which work for every guild)
See message system
Returns the guild language
Returns the message from Messages.json based on guild language
The path in messages object e.g. test.testMessage
{{
"internal": {
"commandsLoaded": "Loaded {size} commands",
"featuresLoaded": "Loaded {size} features"
},
"external": {
"english": {
"test": {
"testMessage": "Hello world!"
}
}
}
}}
Object with placeholders
{
testPlaceholder: 'Test'
}
If message contains placeholder (in this example {testPlaceholder}
) it will be replaced with the value of placeholder (in this example Test
)
Check if the member of interaction has following permissions.
Array of permissions (read more about our permission system here)
See message system
Creates MessageEmbed with default color
MessageEmbed or MessageEmbedData
Creates errorEmbed with given message
The message to set into embed
MessageEmbed or MessageEmbedData
Returns translated FLAGS based on guild language
The flags to translate
Creates paginator
The array of pages to create paginator from
Time of inactivity to auto close paginator. Default: 2 minutes
Message to display after paginator is closed. False
will leave current page. Default: false
Our permission system is simple. You provide an array of groups, and each group contains a list of members and permissions.
Example group:
{
name: 'the name of group',
members: ['Discord user ID or Discord role ID'],
permissions: ['permission']
}
Basic usage is simple. For example permission commands.utils.ban
gives group access to use function, where was provided permission commands.utils.ban
What are they? Wildcard is char (in this handler *
)that gives all permissions from parent node. For example permission commands.utils.*
gives permissions for all functions whose parent node is commands.utils
Negation is a char (in this handler -
)that removes permission from group. For example group has permissions commands.utils.*
and -commands.utils.kick
. This group can run all functions whose parent node is commands.utils
but cannot run command.utils.kick
Group members are simply an array of Discord User IDs or Discord Role IDs
Our message system is based on the Messages file. Example file:
{
"internal": {
"commandsLoaded": "Loaded {size} commands",
"featuresLoaded": "Loaded {size} features"
},
"external": {
"english": {
"slashCommandsLoadAddingError": "Cannot add slash commands to this server, bot must be added with the `application.commands` scope",
"errorEmbedTitle": "Error",
"permissions": {
"CREATE_INSTANT_INVITE": "CREATE INSTANT INVITE",
"KICK_MEMBERS": "KICK MEMBERS",
"BAN_MEMBERS": "BAN MEMBERS",
"ADMINISTRATOR": "ADMINISTRATOR",
"MANAGE_CHANNELS": "MANAGE CHANNELS",
"MANAGE_GUILDS": "MANAGE GUILDS",
"ADD_REACTIONS": "ADD REACTIONS",
"VIEW_AUDIT_LOGS": "VIEW AUDIT LOGS",
"PRIORITY_SPEAKER": "PRIORITY SPEAKER",
"STREAM": "STREAM",
"VIEW_CHANNEL": "VIEW CHANNEL",
"SEND_MESSAGES": "SEND MESSAGES",
"SEND_TTS_MESSAGES": "SEND TTS MESSAGES",
"MANAGE_MESSAGES": "MANAGE MESSAGES",
"EMBED_LINKS": "EMBED LINKS",
"ATTACH_FILES": "ATTACH FILES",
"READ_MESSAGE_HISTORY": "READ MESSAGE HISTORY",
"MENTION_EVERYONE": "MENTION EVERYONE",
"USE_EXTERNAL_EMOJIS": "USE EXTERNAL EMOJIS",
"VIEW_GUILD_INSHIGHTS": "VIEW GUILD INSHIGHTS",
"CONNECT": "CONNECT",
"SPEAK": "SPEAK",
"MUTE_MEMBERS": "MUTE MEMBERS",
"DEAFEN_MEMBERS": "DEAFEN MEMBERS",
"MOVE_MEMBERS": "MOVE MEMBERS",
"USE_VAD": "USE VAD",
"CHANGE_NICKNAMES": "CHANGE NICKNAMES",
"MANAGE_NICKNAMES": "MANAGE NICKNAMES",
"MANAGE_ROLES": "MANAGE ROLES",
"MANAGE_WEBHOOKS": "MANAGE WEBHOOKS",
"MANAGE_EMOJIS_AND_STICKERS": "MANAGE EMOJIS AND STICKERS",
"USE_APPLICATION_COMMANDS": "USE APPLICATION COMMANDS",
"REQUEST_TO_SPEAK": "REQUEST TO SPEAK",
"MMANAGE_THREADS": "MANAGE THREADS",
"USE_PUBLIC_THREADS": "USE PUBLIC THREADS",
"USE_EXTERNAL_STICKERS": "USE EXTERNAL STICKERS"
},
"errors": {
"noPermissions": "You don't have required permissions to perform this action. Required permissions: {permissions}",
"noBotPermissions": "Bot does not have required permissions to perform this action. Required permissions: {permissions}",
"commandDisabled": "Sorry. This command was disabled by developers",
"paginatorNoPermissions": "You can't use the paginator if it isn't your"
},
"internalError": {
"title": "Bot error",
"description": "An error occurred while executing this command"
},
"commands": {
"test": {
"description": "Test command",
"messages": {
"test": "ok"
}
}
}
}
}
}
Internal messages are messages, that will be displayed in the console. You can get internal message by <instance>.getMessage
External messages are messages, that will be displayed in the guild, so they are divided into different languages. You can get external message based on language by <guild>.getMessage
Command messages are a part of external messages. You can use it to specify command description and command options description. Example:
"commands": {
"test": {
"description": "Test command",
"messages": {
"test": "ok"
}
}
}
Messages
in command object are simply messages, that can you get with <interaction>.getMessage
{
"internal": {
"test": "Hello {testPlaceholder}"
}
}
<instance>.getMessage("test", {
testPlaceholder: "World!"
})
If message contains placeholder (in this example {testPlaceholder}
) it will be replaced with the value of placeholder (in this example World!
)