0.0.1-dev.0 • Published 4 years ago

@braveesnow/megumin v0.0.1-dev.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Megumin - A Simple discord.js Framework

Welcome to the megumin project! As of right now, megumin is a work-in-progress and really shouldn't be used unless you just need a simple command handler.

Getting started

Do keep in mind that this is a work-in-progress, so megumin is an incomplete project. However, if you really want to work with this framework, you can add it to your project by using the command below:

npm install --save megumin

Be warned, there will be constant changes, so you might also have to modify your source code as well.

Usage

Below is a basic example of creating a Discord bot with megumin:

const Discord = require('discord.js');
const { CommandHandler } = require('megumin');
const client = new Discord.Client();

// Creating a command handler
const commandHandler = new CommandHandler(`${__dirname}/commands`, {
    discordClient: client,
    prefix: '.'
});

client.login(process.env.TOKEN);

So what's happening?

First, we import the modules we're going to use. Then we create a command handler by instantiating a new CommandHandler class. The first argument that we passed was the directory to all of our commands.

NOTE: It is recommended to prepend __dirname instead of ./ to your command directory (e.x. Do not use ./commands).

The second parameter we pass is an object with a prefix and discordClient property. Set discordClient to the client you made and prefix to a string or a regular expression for your client to listen to.

Optionally, you can use the setClient() method instead of passing your client inside of the object parameter.

Then we log in. That's it! All you need to do now is create a commands directory and start creating commands! Just be sure to follow the command formatting.

Command Format

All commands that you create should be housed in a category folder residing within the root of your commands folder. For example, commands/utilities/command.js will register the command under the utilities category. An example of creating a command can be seen below:

// commands/utilities/ping.js
module.exports.info = {
    name: 'ping'
}

module.exports.run = function(ctx) {
    ctx.send('Pong!');
}