a-djs-handler v5.1.2
a-djs-handler
A command handler for the discord.js v13 dependancy.
Installation
npm install a-djs-handler --saveyarn add a-djs-handlerUsage
Importing the client and handler.
ES6:
const { MoodyClient, Handler } = require('a-djs-handler');TS:
import { MoodyClient, Handler } from 'a-djs-handler';Creating a new client and handler then start the bot.
const client = new MoodyClient();
const handler = new Handler(client, {
prefix: '!',
token: 'REDCATED',
commandsPath: __dirname + '/commands', // can also use path.join(__dirname, '/commands');
eventsPath: __dirname + 'events',
owners: ['123456789', '987654321'],
mongooseURL: 'url' // not required
});
(async () => {
await handler.registerDefaultEvents(); // optional
await handler.start();
})();Example of a command.
app/bot/commands/fun/TestCommand.js
const { BaseCommand } = require('a-djs-handler');
module.exports = class TestCommand extends BaseCommand {
constructor() {
super({
name: 'test',
category: 'fun',
description: 'Test command.',
[...]
});
}
async run(client, message, args) {
await message.channel.send('This is a test command.');
}
}Example of an event.
app/bot/events/ready/ReadyEvent.js
const { BaseEvent } = require('a-djs-handler');
module.exports = class ReadyEvent extends BaseEvent {
constructor() {
super('ready');
}
async run(handler) {
console.log(`${handler.client.username} is ready!`);
}
}Classes/Methods
Documentation for most classes, interfaces and methods.
Handler
The handler responsible for starting the client, handling commands and events.
Parameters:
client: MoodyClient | ClientThe MoodyClient or Client for the handler.options: HandlerOptionsThe options for the handler.
Properities:
clientThe client initialized with the handler.optionsThe options supplied to the handler.utilVarious utility methods to parse arguments.
Methods:
registerDefaultEvents(): HandlerRegisters the default events for the client, which are:readyandmessage.start()Registers the commands and events then starts the client.prompt(message: Message, msg: string | MessageEmbed, options: PromptOptions, user?: User | null)Starts a new prompt for the user, credits to gt-c.
MoodyClient
Custom client for the command handler, extends Client.
Parameters:
options?: ClientOptionsOptions for the client.
Properities:
player: DistubeMusic player for the client, extends Distube.
Methods:
generateKey(length: number)Generates a random string.wait(ms: number)Promise to stop the code until x ms has passed.
BaseCommand
The base command for commands to extend.
Paramaters:
options: CommandOptionsThe options for the command.
Methods:
run(client: MoodyClient | Client, message: Message, args: Array<string>)The run method for the command.
BaseEvent
The base event for events to extend.
Paramaters:
name: stringThe name of the event.
Methods:
run(handler: Handler, ...args: any)The run method for the event.
prompt(client: MoodyClient | Client, message: Message, msg: string | MessageEmbed, options: PromptOptions, user?: User | null)
Prompts the user, credits to gt-c.
Returns: Collection of values collected from the user.
Interfaces
HandlerOptions
prefix: stringThe prefix for the bot.token: stringThe token to run the bot.commandsPath: stringThe commands directory.eventsPath?: stringThe events directory.owners?: Array<string>List of owners, owners get access to commands such as eval.mongooseURL?: stringMongoDB URL if present, starts a MongoDB connection.
CommandOptions
name: stringName of the command.category: stringThe category the command belongs to.description: stringThe description of the command.aliases?: Array<string>Aliases for the command.usage?: stringThe usage for the command.accessableby?: stringWho can access the command.cooldown?: numberThe cooldowns for the command in seconds.ownerOnly?: booleanWhether only the owner can run the command.userPermissions?: Array<PermissionString>Required permissions for the command.botPermissions?: Array<PermissionString>Required permissions for the bot.examples?: Array<string>Examples for the command.userRoles?: Array<string | RoleResolvable | Role>Roles that can use the command.guildOnly?: booleanWhether the command can only run in guilds.
3 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago