slasher.js
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

slasher.js - a slash command framework for Discord.js

NPM version NPM downloads

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, but I've found it hard to integrate with Discord.js and to leverage the type-safety of TypeScript.

Example bot

// 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);
// 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

Package Sidebar

Install

npm i slasher.js

Weekly Downloads

1

Version

0.2.0

License

Apache-2.0

Unpacked Size

53.6 kB

Total Files

39

Last publish

Collaborators

  • neoney