@distype/cmd
TypeScript icon, indicating that this package has built-in type declarations

0.10.1 • Public • Published

@distype/cmd

About

A command handler for Distype.

How it works

Commands are made via builders (example below), and are then pushed to the command handler to be executed whenever an interaction is received. This library also includes builders for other components, including embeds, modals, and message components.

Command execute methods use a command context to allow you to access useful variables, such as the client and information about the command.

img

Command parameters are dynamically typed on the command context

Example Bot

import { Client } from 'distype';
import { CommandHandler } from '@distype/cmd';

const client = new Client(YOUR_BOT_TOKEN);

// Create the command handler.
const commandHandler = new CommandHandler(client);

// Create a command.
const fooCommand = new ChatCommand()
    .setName(`foo`)
    .setDescription(`Foo command`)
    .addStringParameter(true, `bar`, `Describe bar`)
    .addUserParameter(true, `baz`, `Which user is baz?`)
    .setExecute((ctx) => {
        ctx.send(`You said bar is "${ctx.parameters.bar}", and that ${ctx.parameters.baz.user.username} is baz!`);
    });

// Save the foo command to the command handler.
commandHandler.bindCommand(fooCommand);

client.gateway.on(`SHARDS_RUNNING`, () => {
    // Pushes saved commands to your application.
    commandHandler.push();
});

client.gateway.connect();

Note that Discord API typings are for API version 10, and are from discord-api-types. While you can still specify different API versions to be used, it is not recommended.

Installation

@distype/cmd can be installed via npm.

npm install @distype/cmd

Prerequisites

Package Sidebar

Install

npm i @distype/cmd

Weekly Downloads

15

Version

0.10.1

License

Apache-2.0

Unpacked Size

186 kB

Total Files

51

Last publish

Collaborators

  • br88c