Archived
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.
a8efeae9ccc7d70403f71bb496e7f8c4e61adeb6
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
- Visit Discord Developer Portal and create an app
- Navigate to the Bot section and register a bot
- Navigate to OAuth 2 section, select bot and application.commands scopes and check bot permissions
- Copy the link and add your bot to the servers
Creating application
- Create empty directory
- Run
npm init -yoryarn init -y - Add the CommandBot package
// npm
npm install commandbot@latest
// yarn
yarn add commandbot@latest
- Create index.js file
- 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";
- Initialize the bot instance
const bot = new Bot({
name: "YOUR_BOT_NAME",
prefix: "BOT_PREFIX",
parameterSeparator: ",",
clientOptions: {
intents: [..."DISCORD_API_INTENTS"],
},
token: "DISCORD_BOT_TOKEN",
applicationId: "APPLICATION_ID",
});
Properties (* - required):
- name* - string - bot name
- prefix - string - bot prefix to use with text commands (if undefined, only slash commands will be available)
- parameterSeparator - string - used to separate parameters from messages (default: ',')
- clientOptions - ClientOptions - Discord.js client options
- token* - string - Discord bot token
- applicationId* - string - Discord application ID
- Create and add commands to the Bot instance (see Commands)
- Start your bot
bot.start(
port, // If passed, the application will create a HTTP server
true // If true or undefined, the app will register all slash commands in the Discord API
);
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
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
Releases
40
CommandBot 4.2.0
Latest
Languages
TypeScript
99.8%
Shell
0.2%