3.0.0-rc5 • Published 4 years ago

commandbot v3.0.0-rc5

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

CommandBot

A Discord.js based framework that makes creating Discord bots easy and fast.

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 and add your bot to the servers

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 file
  2. Import the CommandBot package
// CommonJS
const { Bot, Command } = require("commandbot");

// ES Modules (to use ESM add "type": "module" to your package.json file)
import { Bot, Command } from "commandbot";
  1. Initialize the bot instance
const bot = new Bot({
    name: "YOUR_BOT_NAME",
    prefix: "BOT_PREFIX", // bot prefix (optional) (if undefined, only slash commands will be available)
    argumentSeparator: ",", // used to separate parameters from messages (optional)
    clientOptions: {
        intents: [..."DISCORD_API_INTENTS"],
    }, // Discord.js ClientOptions (optional)
    token: "DISCORD_BOT_TOKEN", // Discord bot token
    applicationId: "APPLICATION_ID", // Discord application ID used to register slash commands
});

Links

  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
    true // If true, the app will register all slash commands in the Discord API (it's recommended setting it to false after registering to avoid reaching daily quota)
);

Commands

To create a command, initialize a Command object

Example:

const cmdGreet = new Command({
    name: "greet",
    parameters: [
        {
            name: "name",
            description: "Name that will be greeted",
            optional: true,
            type: "string",
        },
    ],
    aliases: ["hello"],
    description: "Welcomes someone",
    usage: "[name]",
    permissionCheck: "ALL",
    permissions: ["SEND_MESSAGES"],
    guilds: undefined,
    visible: true,
    slash: true,
    annouceSuccess: true,
    function: function(p. m) {
        if(p('name')) {
            return `Hello, ${p('name')}!`
        }
        else {
            return 'Hello!'
        }
    }
});

// Register
bot.commands.add(cmdGreet)

Properties (* - required):

  • name* - string - command name
  • parameters - ParameterSchema[] - list of parameters (see Parameters)
  • aliases - string | string[] - list of alternative strings that can call this command (not available for slash commands)
  • description - string - command description
  • usage - string - command usage visible in the help message (if not defined, usage string will be automatically generated based on defined parameters)
  • permissionCheck - "ALL" | "ANY" - whether to check if caller has all defined permission or at least one of them
  • permissions - PermissionResolvable | (m?: Message | CommandInteraction) => boolean - permissions required to run this command
  • guilds - string[] - list of servers IDs in which this command will be available (if slash command)
  • visible - boolean - whether this command is visible in the help message
  • slash - boolean - whether this command should be registered as a slash command
  • announceSuccess - boolean - whether a command reply should be sent automatically if no other response is defined or the reply should be deleted
  • function* - (p: function, m?: Message | CommandInteraction) => void | MessageEmbed | string | ReplyMessageOptions - function that will be executed on call
    • Arguments
      • p - function - call this function with parameter name to fetch parameter value
      • m? - Message | CommandInteraction - interaction object

Register your command in bot client using:

bot.commands.add(cmd);

where cmd is your Command object

4.1.0-beta3a

4 years ago

4.1.0-beta1

4 years ago

4.1.0-beta2

4 years ago

4.1.0-beta3

4 years ago

4.0.1

4 years ago

4.2.0

4 years ago

4.0.2

4 years ago

4.1.0-t

4 years ago

4.1.0

4 years ago

4.0.0-rc2

4 years ago

4.0.0

4 years ago

4.0.0-rc2a

4 years ago

4.0.0-rc1

4 years ago

4.0.0-beta7a

4 years ago

4.0.0-beta7

4 years ago

4.0.0-beta6a

4 years ago

3.1.2

4 years ago

4.0.0-beta6

4 years ago

4.0.0-beta5a

4 years ago

4.0.0-beta5

4 years ago

4.0.0-beta4

4 years ago

4.0.0-beta3

4 years ago

4.0.0-beta1.1

4 years ago

4.0.0-beta1

4 years ago

4.0.0-beta2

4 years ago

4.0.0-alpha2

4 years ago

4.0.0-alpha1

4 years ago

3.2.0-beta1

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.1.0-beta1

4 years ago

3.0.0

4 years ago

3.0.0-rc5

4 years ago

3.0.0-rc4

4 years ago

3.0.0-s-beta1d

4 years ago

3.0.0-s-beta1e

4 years ago

3.0.0-rc2

4 years ago

3.0.0-rc1

4 years ago

3.0.0-rc3

4 years ago

3.0.0-s-beta1b

4 years ago

3.0.0-s-beta1c

4 years ago

3.0.0-s-beta1a

4 years ago

3.0.0-s-beta1

4 years ago

3.0.0-beta2

4 years ago

2.0.2

4 years ago

3.0.0-beta2a

4 years ago

3.0.0-beta1

4 years ago

2.1.0-beta1

4 years ago

2.0.0-beta5

4 years ago

2.0.0-test1

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

2.0.0-beta3

4 years ago

2.0.0-beta4

4 years ago

2.0.0-beta2b

4 years ago

2.0.0-beta2

4 years ago

2.0.0-beta

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.0

4 years ago

1.0.0-test2

4 years ago

1.0.0-test

4 years ago