latecmds v0.1.0
��#
A command handler for Discord.JS v13 bots.
Warnings
This documentation may or may not be hard to keep up (at least to me when editing this).
This command handler will only work with javascript files and not typescript. (Feature will come in the future)
NO SUPPORT FOR SLASH COMMANDS
Table of Contents
Installation
NPM
npm i latecmds
Setting up
After you install the package, you will need to add it to your bot.
const Discord = require("discord.js")
const client = new Discord.Client({
intents: 513
})
const latecmds = require("latecmds")
client.on("ready", () => {
new latecmds(client, {
prefix: "!", // Default will be ?
commandsDir: "cmds", // Default will be "commands"
featuresDir: "feats", // Default will be "features"
mongoUri: "MongoDB URI", // Needed for guild prefixes and cooldowns
dbOptions: {
keepAlive: true,
useNewUrlParser: true,
useUnifiedTopology: true
}, // MongoDB options, Default will be keepAlive
showWarns: false, // Default will be true
categories: [
{
name: "Fun",
emoji: "=��"
},
{
name: "Utility",
emoji: "=�'�",
hidden: true // Hidden categories will only show when an admin/bot owner uses the help command
}
], // 2 default catergories being "Config" and "Help"
color: 0x00FF00, // Default will be 0x7289DA
botOwner: ["454882470306113872"],
testServers: ["153841427033895615"],
})
})
client.login("token")
Creating a command
After you set up latecmds, add a js file in the commandsDir folder.
// ping.js
module.exports = {
start: ({ message, args }) => {
message.channel.send("Pong!")
}
}
When running !ping, it will send "Pong!".
If you want to specify a name for the command, you can pass in the "name" property.
// ping.js
module.exports = {
name: "ping",
start: ({ message, args }) => {
message.channel.send("Pong!")
}
}
Command arguments
You can add arguments to your commands.
// ping.js
module.exports = {
minArgs: 1, // Default will be 0
maxArgs: -1, // Default will be 0, -1 means unlimited
start: ({ message, args }) => {
message.channel.send(`Pong! + ${args.join(" ")}`)
}
}
Command Aliases
Aliases for the same command
// ping.js
module.exports = {
aliases: ["p"],
start: ({ message, args }) => {
message.channel.send(`Pong!`)
}
}
The command can be ran by using !ping or !p.
Command Categories and Description
Category is a way to organize commands.
Description is a way to describe the command.
Both are used in the help command.
Both are required for slash commands in the future.
// ping.js
module.exports = {
category: "Fun",
description: "Test command!",
start: ({ message, args }) => {
message.channel.send(`Pong!`)
}
}
Command Permissions
Command permissions are used to determine if a user can run a command according to their permissions.
Example:
// ping.js
module.exports = {
permissions: ["MANAGE_MESSAGES"],
start: ({ message, args }) => {
message.channel.send(`Pong!`)
}
}
Bot Owner Only Commands
Self explanatory, only the bot owner can use these commands.
First you need to declare one or more user ids in the botOwner array.
new latecmds(client, {
botOwner: ["454882470306113872", "218404789723493888"],
})
Then you can use the botOwner
option like so:
module.exports = {
botOwner: true,
start: ({ message, args }) => {
message.channel.send("You are the bot owner!")
}
}
Test Server Commands
Similar to bot owner commands, but only for test servers.
Declare one or more server ids in the testServers array.
new latecmds(client, {
testServers: ["153841427033895615", "732956239079181824"],
})
Then you can use the testServers
option like so:
module.exports = {
testServers: true,
start: ({ message, args }) => {
message.channel.send("You are in a test server!")
}
}
Command Cooldowns
Command cooldowns are used to prevent a user from spamming a command.
Bot owners bypass cooldowns.
They can use the cooldown
option like so:
module.exports = {
cooldown: "5s", // 5 seconds
start: ({ message, args }) => {
message.channel.send("Pong!")
}
}
Cooldown types are:
Character | Duration | Min | Max | Example |
---|---|---|---|---|
s | Seconds | 1 | 60 | 5s |
m | Minutes | 1 | 60 | 5m |
h | Hours | 1 | 24 | 5h |
d | Days | 1 | 365 | 5d |
Global Command Cooldowns
Like command cooldowns, but for everyone in a guild.
They can use the globalCooldown
option like so:
module.exports = {
globalCooldown: "5s", // 5 seconds
start: ({ message, args }) => {
message.channel.send("Pong!")
}
}
Types are the same as above.
Disabling a command
You can use a command that is built in to disable it.
[PREFIX]command {Disable/Enable} [command]
Creating a feature
Making a feature is as easy and similar as making a command (and pie! not included.)
Make a js file in the featuresDir folder.
// log.js
module.exports = (client) => {
client.on("messageCreate", (message) => {
console.log(`${message.author.tag}: ${message.content}`)
})
}
A feature is actively running while the bot is online.
Configuring a feature
Coming soon!
Disabling a feature
Similar to disabling a command.
You can use a built in command to disable a feature.
[PREFIX]feature {Disable/Enable} [command]
2 years ago