a-djs-handler v5.1.2
a-djs-handler
A command handler for the discord.js v13 dependancy.
Installation
npm install a-djs-handler --save
yarn add a-djs-handler
Usage
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 | Client
The MoodyClient or Client for the handler.options: HandlerOptions
The options for the handler.
Properities:
client
The client initialized with the handler.options
The options supplied to the handler.util
Various utility methods to parse arguments.
Methods:
registerDefaultEvents(): Handler
Registers the default events for the client, which are:ready
andmessage
.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?: ClientOptions
Options for the client.
Properities:
player: Distube
Music 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: CommandOptions
The 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: string
The 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: string
The prefix for the bot.token: string
The token to run the bot.commandsPath: string
The commands directory.eventsPath?: string
The events directory.owners?: Array<string>
List of owners, owners get access to commands such as eval.mongooseURL?: string
MongoDB URL if present, starts a MongoDB connection.
CommandOptions
name: string
Name of the command.category: string
The category the command belongs to.description: string
The description of the command.aliases?: Array<string>
Aliases for the command.usage?: string
The usage for the command.accessableby?: string
Who can access the command.cooldown?: number
The cooldowns for the command in seconds.ownerOnly?: boolean
Whether 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?: boolean
Whether the command can only run in guilds.
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
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