discord.js-handler
v1.3.2
Published
Lightweight event and command handler for a discord.js project
Downloads
18
Maintainers
Readme
discord.js-handler
Features 📋
- Organized and class-oriented
- CommonJS and EcmaScript friendly
- Typings included
- Categories and recursive events and commands
Installation 🔥
npm 🐿️
npm install discord.js-handler
Yarn 🧶
yarn add discord.js-handler
Usage 🚀
Activation example ✔️
const { Client } = require('discord.js');
const { Handler } = require('discord.js-handler');
const handler = new Handler({
client: new Client(),
token: 'TOKEN',
eventsFolder: './events',
commandsFolder: './commands',
});
try {
handler.login();
handler.run();
} catch (e) {
console.error(e);
}
Event example 📡
const { EventListener } = require('discord.js-handler');
module.exports = class MessageEvent extends EventListener {
constructor() {
super({
event: 'message',
listener: async ({ handler }, message) => {
try {
await handler.importCommands('PREFIX', message);
await message.react('💡');
} catch (e) {
console.error(e);
}
},
});
}
};
Command example 📡
const { CommandListener } = require('discord.js-handler');
module.exports = class PingCommand extends CommandListener {
constructor() {
const parameters = {
aliases: ['ping', 'pong'],
listener: async ({ client, message }) => {
try {
await message.reply(`Pong! :ping_pong: ${Math.round(client.ws.ping)}ms`);
await message.delete();
} catch (e) {
console.error(e);
}
},
};
super(parameters);
}
};
Warnings ⚠️
When using commands with the handler, you must specify the commands' folder in the handler settings (commandsFolder
parameter) and have a message event, in which you call the importCommands
method from the handler instance (Handler.importCommands()
), otherwise the commands will not be called (As specified in the event example)
This happens because the handler needs a prefix, and it must be defined on the message event, because you could want the prefix to be dynamic (change from guild to guild)
Login and token management done by the handler is completely optional. If you prefer doing so, create the client instance and login by yourself using discord.js
Feedback 👥
If you want to report an error or give a suggestion, please refer to the following links
License 📝
MIT - hSel3triK