fero-dc v3.0.5
Introduction
Fero-DC is a discord.js library that does all the structures for you.
You get a completely different Client class that has a built-in command/event/slash command handler and other amazing features.
You also get a Command class and Event class for their respective handlers.
More will be added in the future.
Installation
NPM
npm install --save fero-dc
Yarn
yarn add fero-dc
Usage
Note: In TypeScript, when exporting commands and events, export them under:
export const command = new Command()
and
export const event = new Event()
Do not export as default.
Client
You will first need a .env file in your main directory and a config.json somewhere.
Main JS File
const { Client } = require("fero-dc");
const { join } = require("path");
const cwd = process.cwd();
new Client(
{
config: join(cwd, "src", "Data", "config.json"), // Path to your config file (use absolute paths)
commands: join(cwd, "src", "Commands"), // Path to your commands directory
events: join(cwd, "src", "Events") // Path to your events directory
},
{} /* Modules, anything you put in here will result inside the client (ex: { discord: require("discord.js") } -> client.discord is now the discord.js library)*/
);
Config JSON File
{
"_comments": {
"prefix": "The default prefix of the bot",
"tokenName": "The name of the token variable in the .env file",
"permissionData": "The permission data to check with when doing client.checkPermissions, basically set any key to an array of role IDs or permissions",
"commandLoadedMessage": "Whether or not to print to the console that a command was loaded",
"eventLoadedMessage": "Whether or not to print to the console that an event was loaded",
"builtInHelpCommand": "The options for the built-in help command, can either be false or MessageEmbedOptions + slashCommand: boolean",
"deleteUnusedSlashCommands": "Whether or not to delete slash commands that don't appear in the commands directory"
},
"prefix": "!",
"tokenName": "TOKEN",
"permissionData": { "MOD": ["ROLE ID"] },
"commandLoadedMessage": true,
"eventLoadedMessage": true,
"builtInHelpCommand": { "slashCommand": true, "color": "RANDOM" },
"deleteUnusedSlashCommands": false
}
ENV File
TOKEN = BOTTOKEN
Command
Create a JS file in your Commands directory (Allows 1 depth folder nesting)
Command JS File
const { Command } = require("fero-dc");
module.exports = new Command({
name: "ping", // The name of the command
description: "Shows the bot's ping", // The description of the command
aliases: [], // The aliases (secondary names) of the command
permissions: ["SEND_MESSAGES"], // The permissions required to use the command
type: "BOTH", // The type of the command (BOTH, SLASH, TEXT) (tells the client if the command is a slash command or not)
category: "utility", // The category of the command
usage: "!ping <test: string>", // The way to use the command in Discord (A usage is already created with the args of the command, I don't recommend using this)
args: [
{
name: "test",
description: "This is a test",
required: true,
type: "string"
}
], // The arguments to convert in the run function
slashCommandOptions: [
{
name: "test",
description: "This is a test",
type: "STRING",
required: true
}
] // The options to register with the slash command
},
async (message, args, client, test) => {
message.reply(test); // !ping testString -> bot replies "testString"
} // The function that runs when the command is run
);
Event
Create a JS file in your Events directory (Allows 1 depth folder nesting)
Event JS File
const { Event } = require("fero-dc");
module.exports = new Event("messageCreate", async (client, message) => {
const prefix = client.prefix(message.guild);
if (
message.author.bot ||
!message.guild ||
!prefix ||
!message.content.startsWith(prefix)
)
return;
const [cmd, ...args] = message.content.substring(prefix.length).split(/ +/);
const command = client.commands.find(
c =>
c.name.toLowerCase() == cmd.toLowerCase() ||
c.aliases.map(v => v.toLowerCase()).includes(cmd.toLowerCase())
);
if (!command) return message.reply(`${cmd} is not a valid command!`);
const perm = client.checkPermissions(command.permissions, message.member);
if (!perm)
return message.reply(
"You do not have the correct permissions to use this command!"
);
client.runCommand(command, message, args);
});
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago