# djs-handlers

> Extended client functionlity, command and event handler for discord.js v14.

Latest version **1.0.6** (published 2023-04-17) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2023-04-17 |
| First published | 2023-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.9.0 |
| Dependencies | 2 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | defnot001 |
| Maintainers | defnot001 |
| Keywords | discord.js, typescript, npm-package |

## Links

- npm: https://www.npmjs.com/package/djs-handlers
- Repository: https://github.com/defnot001/djs-handlers
- Issues: https://github.com/defnot001/djs-handlers/issues
- npm.io page: https://npm.io/package/djs-handlers

## Dependencies (2)

- [glob](https://npm.io/package/glob.md) ^8.1.0
- [discord.js](https://npm.io/package/discord.js.md) ^14.9.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2023-04-17
- 1.0.5 — 2023-01-26
- 1.0.4 — 2023-01-26
- 1.0.3 — 2023-01-26
- 1.0.2 — 2023-01-25
- 1.0.1 — 2023-01-23
- 1.0.0 — 2023-01-23
- 0.0.1 — 2023-01-22

## README

# djs-handlers

Small package for [discord.js](https://discord.js.org/#/) written in [Typescript](https://www.typescriptlang.org/) that exports 3 classes and the corresponding types:

- Command
- Event
- ExtendedClient

First, you need to install the package using your package manager.

```bash
npm install djs-handlers
```

### ExtendedClient

The `ExtendedClient` holds a `Collection()` of commands and has 2 methods that are exposed to the user.

To use the client, you first need to `import` it and then instantiate the class.

```ts
import { ExtendedClient } from 'djs-handlers';
import { GatewayIntentBits, Partials } from 'discord.js';

const client = new ExtendedClient{
  intents: [
    GatewayIntentBits.Guilds,
  ],
  partials: [Partials.GuildMember],
}

client.start({
  botToken: 'your discord token',
  guildID: 'your guild id, if you want to register the commands to a guild',
  commandsPath: './path/to/commandfolder',
  eventsPath: './path/to/eventfolder',
  type: 'commonJS',
  globalCommands: false,
  registerCommands: true,
})
```

The `global` property accepts a boolean indicating wether you want to register the commands to your application rather than a guild.

The `registerCommands` property accepts a boolean indicating wether you want to register the commmands on startup. You can change this during development to prevent spamming the API.

You can also remove all commands from your guild or application by using the `remove()` method.

```ts
client.removeCommands();
```

Inside your sources folder, create 2 directories with the names `commands` and `events`. Those hold all your events and the corresponding code and all your commands.

To create a new command, create a new file in `src/commands/ping.ts`.

```ts
import { Command } from 'djs-handlers'

export default new Command({
  name: 'ping',
  description: 'Pings a user!',
  options: [
    {
      name: 'target',
      description: 'The user you want to ping.',
      type: ApplicationCommandOptionType.User,
      required: true,
    }
  ]
  execute: async ({ interaction, args }) => {
    const targetUser = args.getUser('target')

    await interaction.reply(`<@${targetUser.id}>`)
  }
});
```

To create a new event, create a new file in `src/commands/ready.ts`.

```ts
import { Event } from 'djs-handlers';

export default new Event('ready', (client) => {
  console.log(`Bot is ready! Logged in as ${client.user.tag}`);
});
```

If you want to jumpstart your development process, make sure to check out my [djs-template repository](https://github.com/defnot001/djs-template) which provides you with examples and a working layout. Make sure to checkout the branch you are interested in (Typescript, CommonJS, ESModules).

If you find any issues or have suggestions please make sure to report them on the [issue tracker](https://github.com/defnot001/djs-handlers/issues).

You can also write me an [email](mailto:defnot001@gmail.com) and/or join my [discord server](https://discord.gg/wmJ3WBYcZF).

Thank you for using my repository and good luck with your next Discord Bot!

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