README
Powered by Discord.js
I. About
A package for managing Discord Slash Commands. For an in-depth documentation visit the official website. For users who want to opt for a similar package with a database manager, check out @ming-suhi/djs-manager from the same developer.
II. Getting Started
A. Installation
Run npm install on the command line or terminal.
npm install @ming-suhi/djs-local-manager
Run npm ci to install dependencies.
npm ci
B. Setting environment
- Create a
.env
file in the root directory
BOT_TOKEN =
COMMANDS_FOLDER =
Get the Discord bot's token and store it as
BOT_TOKEN
.Create a folder to hold command files. Store the folder path from the root as
COMMANDS_FOLDER
.
C. Setting bot
- Create an instance of Discord Client
const Discord = require('discord.js');
const client = new Discord.Client();
- Attach an instance of Manager Client
const Manager = require('@ming-suhi/djs-local-manager');
client.msdm = new Manager.LocalClient();
- Login bot
client.login(client.msdm.token);
D. Creating commands
Create a file inside the commands folder
Require/import
@ming-suhi/djs-local-manager
const Manager = require('@ming-suhi/djs-local-manager');
- Create and export instance of GlobalCommand
module.exports = new Manager.GlobalCommand(commandData);
Example
const Manager = require('@ming-suhi/djs-local-manager');
module.exports = new Manager.GlobalCommand({
name: 'ping',
description: 'pings bot to get latency',
permissions: ["SEND_MESSAGES"],
async execute(interaction) {
//send latency to channel
interaction.sendMessage(`Bot ping is: ${Math.round(interaction.client.ws.ping)}ms`);
}
});
E. Registering commands
- Listen to
ready
//Triggers on ready
client.on('ready', async() => {
//code here
});
- Sync commands
client.msdm.syncCommands(client);
F. Handling commands
- Listen to
INTERACTION_CREATE
//Triggered on Slash Commands
client.ws.on('INTERACTION_CREATE', async request => {
//code here
})
- Create an instance of Manager Interaction
const interaction = new Manager.Interaction(client, request);
3. Execute requested command
client.msdm.matchCommand(interaction);
G. Accessing Manager through interaction
- Access Discord Client instance through the client property of interaction
const client = interaction.client;
- Access manager through the property which you have attached it to(refer to C.2)
const manager = client.msdm;
III. Contributing
A. Issues
This project uses GitHub Issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue.
For help and questions about using this project, please open a GitHub issue.
B. Pull requests
Fork the project.
Create a topic branch from master.
Make some commits to improve the project.
Push this branch to your GitHub project.
Open a Pull Request on GitHub.
Discuss, and optionally continue committing.
IV. License
MIT © 明suhi