# @ming-suhi/djs-local-manager

> Manage all Discord Interactions; Slash Commands, Button, and Select Menus

Latest version **3.5.0** (published 2021-07-30) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @ming-suhi/djs-local-manager
pnpm add @ming-suhi/djs-local-manager
yarn add @ming-suhi/djs-local-manager
bun add @ming-suhi/djs-local-manager
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.5.0 |
| Published | 2021-07-30 |
| First published | 2021-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | 明强 |
| Maintainers | ming-suhi |
| Keywords | discord, discord-interactions, discord-slash, discord-buttons, discord-select-menus, discord-slash-commands, discord-manager |

## Links

- npm: https://www.npmjs.com/package/@ming-suhi/djs-local-manager
- Repository: https://github.com/ming-suhi/djs-local-manager
- Homepage: https://github.com/ming-suhi/djs-local-manager#readme
- Issues: https://github.com/ming-suhi/djs-local-manager/issues
- npm.io page: https://npm.io/package/@ming-suhi/djs-local-manager

## Dependencies (2)

- [dotenv](https://npm.io/package/dotenv.md) ^10.0.0
- [discord.js](https://npm.io/package/discord.js.md) ^12.5.3

## Recent versions

- 3.5.0 (latest) — 2021-07-30
- 3.4.1 — 2021-07-16
- 3.4.0 — 2021-07-13
- 3.3.0 — 2021-07-10
- 3.2.1 — 2021-07-09
- 3.2.0 — 2021-07-09
- 3.1.0 — 2021-07-07
- 3.0.0 — 2021-07-06
- 2.0.1 — 2021-07-05
- 2.0.0 — 2021-07-04
- 1.0.0 — 2021-06-21

## README

<p align="center">
  <img src="https://raw.githubusercontent.com/ming-suhi/ming-suhi/master/djs-local-manager.svg" width="100" align="center" />
</p>

<p align="center">
  <a href="https://github.com/ming-suhi/djs-local-manager" target="_blank">
    <strong>@ming-suhi/djs-local-manager</strong>
  </a>
</p>

<p align="center">Powered by Discord.js</p>


## I. About
A package for managing Discord Interaction; Slash Commands, Button, and Select Menus. For an in-depth documentation visit the <a href="https://ming-suhi.github.io/djs-local-manager/" target="_blank">official website</a>. For users who want to opt for a similar package with a database manager, check out <a href="https://github.com/ming-suhi/djs-manager" target="_blank">@ming-suhi/djs-manager</a> 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
```


## B. Setting environment

1. Create a `.env` file in the root directory

    ```env
    BOT_TOKEN = 

    COMMANDS_FOLDER =
    ```

2. Get the Discord bot's token and store it as `BOT_TOKEN`.

3. 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
    ```js
    const Discord = require('discord.js');
    const client = new Discord.Client();
    ```

2. Attach an instance of Manager Client
    ```js
    const Manager = require('@ming-suhi/djs-local-manager');
    client.msdm = new Manager.LocalClient();
    ```

3. Login bot
    ```js
    client.login(client.msdm.token);
    ```

## D. Creating commands

1. Create a file inside the commands folder, file name must be the same as command name

2. Require/import `Command`
    ```js
    const {Command} = require('@ming-suhi/djs-local-manager');
    ```

3. Extend `Command`
    ```js
    const myCommand = new class extends Command {
      constructor() {
        super();
        // Properties here
      }
    }
    ```

4. Set class properties
    ```js
    this.name = "mycommand";
    this.description = 'my custom command';
    ```

5. Create `execute` method
    ```js
    async execute(service) {
      await service.send({content: 'Your command has been heard'});
    }
    ```

6. Export created class
    ```js
    module.exports = myCommand;
    ```

    Example
    ```js
    const {Command} = require('@ming-suhi/djs-local-manager');

    const ping = new class extends Command {
      constructor() {
        super();
        this.name = "ping";
        this.description = 'pings bot to get latency';
      }

      async execute(service) {
        await service.send({content: 'Pong'});
      }
    }

    module.exports = ping;
    ```


## E. Synching commands

It is suggested to sync commands on client ready. To sync commands just simply call on `syncCommands` method.

```js
client.on('ready', async() => {
  client.msdm.syncCommands(client);
});
```


## F. Setting interaction handler

This step setups an interaction handler that finds the corresponding file for the requested command. Upon receiving a slash command it calls on the executes method of that command. Upon receiving a button interaction it executes the onPress method, while receiving a select menu interaction executes the onSelect method.

```js
client.ws.on('INTERACTION_CREATE', async interaction => {
  client.msdm.handleInteraction(client, interaction);
})
```


## 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

---
_Source: https://npm.io/package/@ming-suhi/djs-local-manager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
