A Discord.js based framework that makes creating Discord bots with support for slash commands easy and fast.
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.
npm init -y
or yarn init -y
// npm
npm install commandbot@latest
// yarn
yarn add commandbot@latest
// CommonJS
const { Bot } = require("commandbot");
// ES Modules (to use ESM add "type": "module" to package.json file)
import { Bot } from "commandbot";
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,
},
});
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.
To create a command, use CommandManager.prototype.add method
Command types
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",
},
ephemeral: "NONE",
function: async (i) => {
const user = await i.get("user").toObject();
return `Hello ${user.toString()}`;
},
});
Command function schema is defined here
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
Pass a list of ParameterSchema objects to parameters property
Example parameter object:
{
name: "user",
description: "User to mention",
optional: false,
type: "user"
}
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')
}
}
}
To create a subcommand create a standard chat command and use ChatCommand.prototype.append method to create and attach subcommands or subcommand groups. To add subcommands to groups use SubCommandGroup.prototype.append.
// Create a chat command
const cmd = bot.commands.add("CHAT", {
name: "parent",
slash: true,
description: "This is a parent",
});
// Create and append a subcommand
cmd.append("COMMAND", {
name: "child",
description: "This is a subcommand",
aliases: ["ch"],
});
// Create and append a subcommand group
const group = cmd.append("GROUP", {
name: "command_group",
description: "This is a subcommand group",
});
// Add a subcommand to the group
group.append({
name: "group_command",
description: "This is a subcommand that is a child of the command_group",
aliases: ["subch"],
});
To invoke subcommands using Discord messages use an argumentSeparator (default: "/").
!parent - "parent" command
!parent/child - "child" command
!parent/command_group - this will invoke the "parent" command
!parent/command_group/group_command - "group_command" command which is a parent of "command_group" group
CommandBot is using EventEmitter that is built into Node.js. You can listen to events using the on method. Event types are available here.
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.
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.
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
Generated using TypeDoc