discord.js-handler v1.3.2
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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago