# node-handlers

> The Best Handlers for Node!

Latest version **0.6.2** (published 2022-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-handlers
pnpm add node-handlers
yarn add node-handlers
bun add node-handlers
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.2 |
| Published | 2022-09-22 |
| First published | 2021-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16.6.0 |
| Dependencies | 2 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Ole_is_lve |
| Maintainers | ole-is-live |
| Keywords | handlers, node, js |

## Links

- npm: https://www.npmjs.com/package/node-handlers
- Repository: https://github.com/Ole-is-live/node-handlers
- Homepage: https://github.com/Ole-is-live/node-handlers#readme
- Issues: https://github.com/Ole-is-live/node-handlers/issues
- npm.io page: https://npm.io/package/node-handlers

## Dependencies (2)

- [fs](https://npm.io/package/fs.md) ^0.0.1-security
- [chalk](https://npm.io/package/chalk.md) ^4.1.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.6.2 (latest) — 2022-09-22
- 0.5.5 (dev) — 2022-04-25
- 0.6.1 — 2022-09-22
- 0.6.0 — 2022-04-25
- 0.5.4 — 2022-04-25
- 0.5.3 — 2022-04-06
- 0.5.2 — 2021-11-10
- 0.5.1 — 2021-10-16
- 0.5.0 — 2021-10-16
- 0.4.4 — 2021-10-16
- 0.4.3 — 2021-10-16
- 0.4.2 — 2021-10-16
- 0.4.1 — 2021-10-16
- 0.3.2 — 2021-10-15
- 0.3.1 — 2021-10-14
- … 13 more at https://npm.io/package/node-handlers/versions

## README

# Node Handlers
## About

Node Handlers is a [Node.js](https://nodejs.org) module that allows you to easily use Handlers in node.js!

At the moment there are only handlers for Discord Bots, more will follow.

## Installation

**Node.js 16.6.0 or newer is required.**  

```sh-session
npm install node-handlers
```


## Example usage

Install all required dependencies:
```sh-session
npm install node-handlers

```

## How to use the Discord Handlers:

### Example Directory Structure
#### This is an example structure for the example below
##### The files named in the example structure are under the example structure
```text
📦 path/to/directory
 ┣📂 commands
 ┃ ┣📂 help
 ┃ ┃ ┗📜 ping.js
 ┃ ┗📜 pong.js
 ┣📂 events
 ┃ ┣📂 interactions
 ┃ ┃ ┗📜 interactionCreate.js
 ┃ ┗📜 ready.js
 ┗📜 index.js
```
>**_Commands can either be placed directly in a folder (e.g. commands) or in a subfolder (e.g. commands/help) 
>in the folder. It's the same for the events: They can 
>either be placed directly in a folder (e.g. events) or in a subfolder (e.g. events/interactions) in the folder._**

### Command Template

```js
// Command Template 'pong.js'
const Discord = require('discord.js');
module.exports = {
    name: "pong",
    description: "Replies with Pong",
    type: 1, // 1 = Command, 2 = User, 3 = Message
    async execute(interaction){
            
            const Pinging = new Discord.MessageEmbed()
            Pinging.setTitle("> __**PONG!**__")

            interaction.reply({embeds: [ Pinging ]});
    }
}
```
### Event Template
```js
// Event Template (Runs when the bot is logged in, 'ready.js')
module.exports = {
	name: 'ready',
	once: true,
	execute(client) {
		console.log(`Ready! Logged in as ${client.user.tag}`);
	},
};
```
```js
// Event Template (Is needed to interact with slash commands, 'InteractionCreate.js')
module.exports = {
	name: 'interactionCreate',
	once: false,
	async execute(interaction, client) {
		if (interaction.isCommand()) {
            
            const command = client.slashcmds.find(cmd => {
                return cmd.name === interaction.commandName
              })
    
            if (!command) return;
    
            try {
                await command.execute(interaction);
            } catch (error) {
                console.error(error);
                await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
            }
        }
	},
};
```

Afterwards we can create a quite simple example bot with the Event and Command Handler:
```js
// This is the 'index.js' from the example structure
const { Discord, Client, Intents} = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]});
const handlers = require('node-handlers');

handlers.dc.events(__dirname + 'PATH TO EVENT FOLDER', client) // e.g. './events'
handlers.dc.commands(__dirname + 'PATH TO COMMAND FOLDER', client) // e.g. './commands'

client.login('YOUR_TOKEN') // Copy from your Application on https://discord.com/developers/applications/<ID>/bot
```



## Links

- [GitHub](https://github.com/Ole-is-live/node-handlers)
- [NPM](https://www.npmjs.com/package/node-handlers)

## Contributing

Before creating an issue, please ensure that it hasn't already been reported, and check the
[documentation](https://www.npmjs.com/package/node-handlers).

---
_Source: https://npm.io/package/node-handlers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
