fire-handler v2.0.0
Contents
Installation
npm i fire-handler --save
npm i dotenv --save // This is optional, you only need it if you want to use a .env file for your token
npm i cdcolours --save // This is optional, we use this for colourful console logs
Setup
JavaScript
// File Name (Main File) - index.js
const colour = require("cdcolours");
const Discord = require("discord.js");
const { fireHandler } = require("fire-handler");
require("dotenv").config();
const client = new Discord.Client();
client.on("ready", () => {
new fireHandler(client, {
commandsDir: "commands", // String - commands directory
eventsDir: "events", // String - events directory
featuresDir: "features", // String - features directory
prefix: "!",
category: "Misc", // String - Default category for commands
pingReply: true, // Boolean - If you want the bot to reply with it's prefix when it gets pinged
devs: [], // Array - Bot Developer ID's for devOnly commands.
defaults: true // Boolean - active default commands
})
console.log(
colour("[READY]", { textColour: "green" }) +
` Successfully logged in as ${client.user.tag}`,
);
});
client.login(process.env.TOKEN);
TypeScript
// File Name (Main File) - index.ts
import colour from "cdcolours";
import * as Discord from "discord.js";
import { fireHandler } from "fire-handler";
import { config as dotenv } from "dotenv";
dotenv()
const client = new Discord.Client();
client.on("ready", () => {
new fireHandler(client, {
commandsDir: "commands", // String - commands directory
eventsDir: "events", // String - events directory
featuresDir: "features", // String - features directory
prefix: "!",
category: "Misc", // String - Default category for commands
pingReply: true, // Boolean - If you want the bot to reply with it's prefix when it gets pinged
devs: [], // Array - Bot Developer ID's for devOnly commands.
defaults: true // Boolean - active default commands
})
console.log(
colour("[READY]", { textColour: "green" }) +
` Successfully logged in as ${client.user!.tag}`,
);
});
client.login(process.env.TOKEN);
Creating a Command
All your command files need to be inside your commands directory. You can have as many sub directories as you want.
Options
name* -- String | The name of the command
aliases - Array | An array of aliases for the command
cooldown - String | Cooldown JUST TO DISPLAY IN HELP MENU
cooldownMessage - String | The response message if the cooldown timeout didn't expired
minArgs - Number | The minimum arguments required for a command
maxArgs - Number | The maximum arguments for a command
argsMessage - String | The response for if a user has too many or not enough arguments for a command
description - String | The command description
usage - String | The command usage
example - String | A example
dev - Boolean | If the command should be locked to developers only (Defined in the main file)
devMessage - String | The response message for if a non-dev runs a developer only command
nsfw - Boolean | If the command should be locked to NSFW channels
nsfwMessage - String | The response message for if a user runs a NSFW command in a SFW channel
permissions - Array | Permissions the user needs to run the command
permissionsMessage - String | The response message for if a user does not have all the required permissions
botPermissions - Array | Permissions the bot requires to run the command
botPermissionsMessage - String | The response message for if the bot does not have the requried permissions to run a command
category - String | The category the command is in
locked - Boolean | Locks the command (default: false)
lockedMessage - String | The response message for a locked command
hidden - Boolean | Makes the command completely invisible for help command (default: false)
hidden2 - Boolean | Makes the command partially invisible for help command (default: false)
Command
JavaScript
// File Name - ping.js
const { MessageEmbed } = require("discord.js");
module.exports = {
name: "ping",
aliases: ["Pong"],
description: "Replies with Pong!",
cooldown: "5s",
cooldownMessage: 'Wait {REMAINING} more to execute this command again!',
//usage: "", it's not needed on this command
//example: "", it's not needed on this command
minArgs: 0,
maxArgs: 0,
argsMessage:
"Incorrect Arguments! There are no arguments required for this command!",
dev: true,
devMessage: "You must be a developer to run this command!",
nsfw: true,
nsfwMessage: "You cannot run this command in SFW channels!",
permissions: ["KICK_MEMBERS"],
permissionsMessage:
"You must have the 'Kick Members' permission to run this command!",
botPermissions: ["EMBED_LINKS"],
botPermissionsMessage:
"I cannot run this command without the 'Embed Links' permission!",
category: "Misc",
locked: true,
lockedMessage: "This command is locked at the moment!",
hidden: true,
hidden2: true,
fire: ({ message, args, client, handler }) => {
/* handler represents fireHandler but don't change the param name you can use callback, execute or run instead of fire */
const embed = new MessageEmbed()
.setColor("#00DCFF")
.setTitle("Pong!");
message.channel.send(embed);
handler.cooldown(message, '5s') // this creates a cooldown
},
};
TypeScript
// File Name - ping.ts
import { MessageEmbed } from "discord.js";
export default {
name: "ping",
aliases: ["Pong"],
description: "Replies with Pong!",
cooldown: "5s",
cooldownMessage: 'Wait {REMAINING} more to execute this command again!',
//usage: "", it's not needed on this command
//example: "", it's not needed on this command
minArgs: 0,
maxArgs: 0,
argsMessage:
"Incorrect Arguments! There are no arguments required for this command!",
dev: true,
devMessage: "You must be a developer to run this command!",
nsfw: true,
nsfwMessage: "You cannot run this command in SFW channels!",
permissions: ["KICK_MEMBERS"],
permissionsMessage:
"You must have the 'Kick Members' permission to run this command!",
botPermissions: ["EMBED_LINKS"],
botPermissionsMessage:
"I cannot run this command without the 'Embed Links' permission!",
category: "Misc",
locked: true,
lockedMessage: "This command is locked at the moment!",
hidden: true,
hidden2: true,
fire: ({ message, args, client, handler }: any) => {
/* handler represents fireHandler but don't change the param name
you can use callback, execute or run instead of fire */
const embed = new MessageEmbed()
.setColor("#00DCFF")
.setTitle("Pong!");
message.channel.send(embed);
handler.cooldown(message, '5s') // this creates a cooldown
},
};
Intellisense
Intellisense is a feature which is only avaible for commands (at the moment). It gives more performance to the developer while creating commands
JavaScript:
// File Name - ping.js
const { MessageEmbed } = require('discord.js')
const { Command } = require('fire-handler') // <--
module.exports = new Command({ // <--
name: "ping",
aliases: ["Pong"],
description: "Replies with Pong!",
cooldown: "5s",
cooldownMessage: 'Wait {REMAINING} more to execute this command again!',
//usage: "", it's not needed on this command
//example: "", it's not needed on this command
minArgs: 0,
maxArgs: 0,
argsMessage:
"Incorrect Arguments! There are no arguments required for this command!",
dev: true,
devMessage: "You must be a developer to run this command!",
nsfw: true,
nsfwMessage: "You cannot run this command in SFW channels!",
permissions: ["KICK_MEMBERS"],
permissionsMessage:
"You must have the 'Kick Members' permission to run this command!",
botPermissions: ["EMBED_LINKS"],
botPermissionsMessage:
"I cannot run this command without the 'Embed Links' permission!",
category: "Misc",
locked: true,
lockedMessage: "This command is locked at the moment!",
hidden: true,
hidden2: true,
fire: ({ message, args, client, handler }) => {
/* handler represents fireHandler but don't change the param name you can use callback, execute or run instead of fire */
const embed = new MessageEmbed()
.setColor("#00DCFF")
.setTitle("Pong!");
message.channel.send(embed);
handler.cooldown(message, '5s') // this creates a cooldown
},
}); // <--
TypeScript
// File Name - ping.ts
import { MessageEmbed } from "discord.js";
import { Command, CommandOptions } from "fire-handler" // <--
export default new Command({ // <--
name: "ping",
aliases: ["Pong"],
description: "Replies with Pong!",
cooldown: "5s",
cooldownMessage: 'Wait {REMAINING} more to execute this command again!',
//usage: "", it's not needed on this command
//example: "", it's not needed on this command
minArgs: 0,
maxArgs: 0,
argsMessage:
"Incorrect Arguments! There are no arguments required for this command!",
dev: true,
devMessage: "You must be a developer to run this command!",
nsfw: true,
nsfwMessage: "You cannot run this command in SFW channels!",
permissions: ["KICK_MEMBERS"],
permissionsMessage:
"You must have the 'Kick Members' permission to run this command!",
botPermissions: ["EMBED_LINKS"],
botPermissionsMessage:
"I cannot run this command without the 'Embed Links' permission!",
category: "Misc",
locked: true,
lockedMessage: "This command is locked at the moment!",
hidden: true,
hidden2: true,
fire: ({ message, args, client, handler }: any) => {
/* handler represents fireHandler but don't change the param name
you can use callback, execute or run instead of fire */
const embed = new MessageEmbed()
.setColor("#00DCFF")
.setTitle("Pong!");
message.channel.send(embed);
handler.cooldown(message, '5s') // this creates a cooldown
},
} as CommandOptions); // <--
Creating an Event
JavaScript
// file name = guildMemberRemove.js
module.exports = (client, member) => { // member is the guildMemberRemove param
console.log(member.user.tag)
}
TypeScript
// file name = guildMemberRemove.ts
import { Client } from "discord.js";
export default (client: Client, member: any) => { // member is the guildMemberRemove param
console.log(member.user!.tag)
}
Creating a feature
JavaScript
// Imagine you need 2 guildMemberRemove events
module.exports = client => {
client.on('guildMemberRemove', member => {
console.log(member.user.tag)
})
}
Typescript
// Imagine you need 2 guildMemberRemove events
import { Client } from "discord.js";
export default (client: Client) => { /* you can import Client from
discord.js and change the any type to Client */
client.on('guildMemberRemove', (member: any) => {
console.log(member.user!.tag)
})
}
Prefixes
fireHandler.prefixes.set('guild id', 'new prefix')
Note: Prefixes are local host, if you have a db make sure to store them in the db and in a loop get all the prefixes and store them in fireHandler.prefixes.set()
fireHandler.prefixes.get('guild id') || fireHandler.prefix
Support and Other
If you need any help or have any suggestions for the package please join our Support Server
This package uses CDColours for the console logs!