# slasher.js

> A framework for Discord slash commands based on Discord.js.

Latest version **0.2.0** (published 2021-10-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install slasher.js
pnpm add slasher.js
yarn add slasher.js
bun add slasher.js
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-10-21 |
| First published | 2021-08-12 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 52.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Michał Minarowski |
| Maintainers | neoney |
| Keywords | discord, slash, commands, interactions, discord.js, bots |

## Links

- npm: https://www.npmjs.com/package/slasher.js
- Repository: https://github.com/n3oney/slasher.js
- Homepage: https://github.com/n3oney/slasher.js#readme
- Issues: https://github.com/n3oney/slasher.js/issues
- npm.io page: https://npm.io/package/slasher.js

## Dependencies (2)

- [discord.js](https://npm.io/package/discord.js.md) ^13.0.1
- [discord-api-types](https://npm.io/package/discord-api-types.md) ^0.22.0

## Recent versions

- 0.2.0 (latest) — 2021-10-21
- 0.1.0 — 2021-08-12

## README

# slasher.js - a slash command framework for Discord.js
<div align="center">
  <a href="https://www.npmjs.com/package/slasher.js"><img src="https://img.shields.io/npm/v/slasher.js?maxAge=3600" alt="NPM version" /></a>
  <a href="https://www.npmjs.com/package/slasher.js"><img src="https://img.shields.io/npm/dt/slasher.js"
  alt="NPM downloads" /></a>
</div>

#### Note: This framework is not yet stable, although it does have enough functionality to let you create a Discord bot that uses slash commands.

## Why?
I've wanted to re-write my bots to use slash commands and haven't been able to find a good framework to simplify the repetitive work. In the past, I've really liked [slash-create](https://github.com/Snazzah/slash-create), but I've found it hard to integrate with Discord.js and to leverage the type-safety of TypeScript.

## Example bot
```ts
// index.ts
import { Client, Intents } from 'discord.js';
import { SlasherClient } from 'slasher.js';
import { PingCommand } from './commands/Ping.command';

const client = new Client({
  intents: [
    Intents.FLAGS.DIRECT_MESSAGES
  ],
});

const slasher = new SlasherClient(client);

client.on('ready', async () => {
  await slasher.commands.registerCommands([
    PingCommand
  ]);
});

client.login(process.env.TOKEN);
```

```ts
// commands/Ping.command.ts
import { BooleanOption, SlasherCommand, SlasherContext, ChannelOption, SlasherClient } from 'slasher.js';

type PingProps = {
  pong?: BooleanOption,
}

export class PingCommand extends SlasherCommand<PingProps> {
  async run(context: SlasherContext<PingProps>) {
    context.interaction.reply({
      content: context.props.pong ? 'Pong!' : 'Yeah, I\'m working fine.'
    });
  }

  constructor(client: SlasherClient) {
    super(client, {
      name: 'ping',
      description: 'It responds for you!',
      options: [{
        type: 'BOOLEAN',
        name: 'pong',
        description: 'Whether it should pong or just... respond.',
        required: false
      }],
      guildId: '12345678'
    });
  }
}
```

## Future plans
- [ ] change the constructor override to a decorator, because it would look nicer and be less scary
- [ ] add support for subcommands

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