@ming-suhi/djs-local-manager-test

Manage Discord Slash Commands in an organized, consistent, and structured manner

Usage no npm install needed!

<script type="module">
  import mingSuhiDjsLocalManagerTest from 'https://cdn.skypack.dev/@ming-suhi/djs-local-manager-test';
</script>

README

@ming-suhi/djs-local-manager

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

  1. Create a .env file in the root directory
BOT_TOKEN = 

COMMANDS_FOLDER =
  1. Get the Discord bot's token and store it as BOT_TOKEN.

  2. Create a folder to hold command files. Store the folder path from the root as COMMANDS_FOLDER.

C. Setting bot

  1. Create an instance of Discord Client
const Discord = require('discord.js');
const client = new Discord.Client();
  1. Attach an instance of Manager Client
const Manager = require('@ming-suhi/djs-local-manager');
client.msdm = new Manager.LocalClient();
  1. Login bot
client.login(client.msdm.token);

D. Creating commands

  1. Create a file inside the commands folder

  2. Require/import @ming-suhi/djs-local-manager

const Manager = require('@ming-suhi/djs-local-manager');
  1. 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

  1. Listen to ready
//Triggers on ready
client.on('ready', async() => {
  //code here
});
  1. Sync commands
client.msdm.syncCommands(client);

F. Handling commands

  1. Listen to INTERACTION_CREATE
//Triggered on Slash Commands
client.ws.on('INTERACTION_CREATE', async request => {
  //code here
})
  1. 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

  1. Access Discord Client instance through the client property of interaction
const client = interaction.client;
  1. 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

  1. Fork the project.

  2. Create a topic branch from master.

  3. Make some commits to improve the project.

  4. Push this branch to your GitHub project.

  5. Open a Pull Request on GitHub.

  6. Discuss, and optionally continue committing.

IV. License

MIT © 明suhi