This repository has been archived on 2025-11-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
2021-08-07 16:14:40 +02:00
2021-06-24 16:21:21 +02:00
2021-11-21 23:28:12 +01:00
2021-11-21 23:28:12 +01:00
2021-11-21 03:01:35 +01:00
2021-11-21 23:46:37 +01:00
2021-11-17 17:11:43 +01:00
2021-06-19 18:35:14 +02:00
2021-11-21 23:46:37 +01:00
2021-11-21 23:28:12 +01:00
2021-07-06 21:14:36 +02:00
2021-07-06 21:14:36 +02:00
2021-09-02 22:45:42 +02:00

CommandBot

A Discord.js based framework that makes creating Discord bots with support for slash commands easy and fast.

Features

  • Support for slash commands, context menu interactions
  • Intuitive usage
  • Flexible
  • Good customization
  • Permission system
  • Built-in help command
  • Built-in information messages
  • Automatic error catching
  • Large documentation in README and using JSDoc
  • Written in TypeScript

Documentation

Reference for available objects and structures is available here. All descriptions can also be accessed from your code editor/IDE. TypeScript declaration files are also included (.d.ts) for some programs (like Visual Studio Code) to give autocompletion suggestions.

Table of contents

Installation

System requirements

  • Node.js 16.6.0 or newer
  • npm or yarn package manager

Creating a project

Registering Discord app

  1. Visit Discord Developer Portal and create an app
  2. Navigate to the Bot section and register a bot
  3. Navigate to OAuth 2 section, select bot and application.commands scopes and check bot permissions
  4. Copy the link, paste it in your web browser and add the bot to a server

Creating application

  1. Create empty directory
  2. Run npm init -y or yarn init -y
  3. Add the CommandBot package
// npm
npm install commandbot@latest

// yarn
yarn add commandbot@latest
  1. Create index.js/index.ts file (TypeScript is a recommended language)
  2. Import the CommandBot package
// CommonJS
const { Bot } = require("commandbot");

// ES Modules (to use ESM add "type": "module" to package.json file)
import { Bot } from "commandbot";
  1. Initialize the bot instance (InitOptions) (list of available intents here)
const bot = new Bot({
    name: "YOUR_BOT_NAME",
    globalPrefix: "!",
    argumentSeparator: ",",
    commandSeparator: "/",
    clientOptions: {
        intents: [..."DISCORD_API_INTENTS"],
    },
    token: "DISCORD_BOT_TOKEN",
    applicationId: "APPLICATION_ID",
    help: {
        enabled: true,
        title: "List of commands",
        usage: "[command name]",
        description: "Show all commands available to use in my fantastic Discord bot.",
        bottomText: "Hello World",
        color: "#0055ff",
        visible: false,
    },
});
  1. Create and add commands to the Bot instance (see Commands)
  2. Start your bot
bot.start(
    port, // If passed, the application will create a HTTP server [type: number (integer)]
    true // If true or undefined, the app will register all slash commands in the Discord API [type: boolean]
);

WARNING! All commands have to be added to the instance before starting the bot. Adding commands while the bot is running is not possible and can cause issues.

Commands

Creating a command

To create a command, use CommandManager.prototype.add method

Command types

  • CHAT - message interactions using command prefixes or slash commands
  • USER - right-click context menu interactions on users
  • MESSAGE - right-click context menu interactions on messages

Chat command example:

bot.commands.add("CHAT", {
    name: "greet",
    parameters: [
        {
            name: "user",
            description: "User to greet",
            optional: false,
            type: "user",
        },
    ],
    aliases: ["hello"],
    description: "Welcome someone to your server",
    usage: "[user]",
    dm: false,
    guilds: ["123456789874561230"],
    slash: true,
    visible: true,
    permissions: {
        resolvable: ["ADMINISTRATOR"],
        checkType: "ANY",
    },
    function: async (i) => {
        const user = await i.get("user").toObject();
        return `Hello ${user.toString()}`;
    },
});

Command function schema is defined here

Parameters

Types

To get an entity ID from ObjectID use the id property. You can also call toObject method to retrieve full entity object from Discord API

Defining

Pass a list of ParameterSchema objects to parameters property

Example parameter object:

{
    name: "user",
    description: "User to mention",
    optional: false,
    type: "user"
}

Reading input value

To read parameter values use InputManager.prototype.get() (passed in the first argument of a command function)

Example:

function: (i) => {
    const userObj = i.get('member', 'user')
    if(userObj) {
        const user = userObj.toObject();
        if(user) {
            return `Hello, ${user.toString()}`
        }
        else {
            throw new Error('User not found')
        }
    }
}

Events

CommandBot is using EventEmitter that is built into Node.js. You can listen to events using the on method. Event types are available here.

Messages

System messages

System messages can be composed and sent automatically when a certain action happens. All message types are available here. Their configuration is stored in Bot.prototype.messages property. Each of these messages can be customized with SystemMessageAppearance objects. There is also a global deleteTimeout property so messages can automatically be deleted after a given time.

Help message

To configure it use the help property in the bot's constructor and pass there a HelpMessageParams object.

WARNING! You can't customize these messages after starting the bot. Changing these properties while the bot is running will have no effect.

Issues

Since this package is created by only 1 person it may contain some bugs or behave weirdly. If you notice any problem, typo etc, please create an issue in the Issues tab on GitHub.

Thank you.

Created with ❤️ by GRZANA

S
Description
Discord.js framework that helps you create your Discord bot. It includes full command system, automatically generated help command and command permission system.
Readme MIT
1.2 MiB
0 Stars 1 Watchers 0 Forks
2022-01-15 17:46:39 +01:00
Languages
TypeScript 99.8%
Shell 0.2%