Skip to content

This package helps you create discord.js commands more easily.

License

Notifications You must be signed in to change notification settings

FlamesX-128/Discord.js_cmds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord.js_cmds v3.0.0

This package works in JavaScript and TypeScript

Places:


Features:

Added:

  • Command interface.
  • Arguments interface.
  • Permissions interface.
  • Parameters.

Change:

  • Element validator.
  • Argument validator.

Plans:

  • Add cooldown in commands.

Parameters:

function readCommands(
	//Prefix that calls the bot.
    prefix: string,

	//Message from discord.
    message: any
): Promise<void>; //Type of value returned.
function readFiles(
	//Bot directory
    directory: string,

	//Command directory
    target: string
): Promise<void>; //Type of value returned.

This applies to the commandBase.

interface TypeCommand {
	//Name of the command to be executed.
    name: string, //Value to be received.

	//Alternative names of the command to run.
    aliases: null | string[], //Value to be received.

	//Command category.
    category: null | string[], //Value to be received.

	//The command will be executed if true.
    activated: boolean; //Value to be received.
}
interface TypeArgs {
	//Argument type to send.
    expectedArgs: null | string[], //Value to be received.

	//Number of arguments.
    numberOfArgs: null | number, //Value to be received.

	//The command is not executed if the arguments are greater than those requested.
    NotMoreArgs: boolean, //Value to be received.

	//Parameters of the arguments to send if there is an error.
    argsError: null | string, //Value to be received.

	//Minimum number of arguments.
    minArgs: null | number, //Value to be received.

	//Maximum number of arguments.
    maxArgs: null | number; //Value to be received.
};
interface TypePerms {
	//It will find if a user has the roles or the permissions.
    alternative: boolean, //Value to be received.

	//Required roles to run the commando.
    requiredRoles: null | string[], //Value to be received.

	//Required permissions to run the commando.
    requiredPerms: null | string[]; //Value to be received.
};

Examples:

Example TS(TypeScript):

package.json

{
  "devDependencies": {
    "@types/node": "^14.14.37",
    "dotenv": "^8.2.0",
    "nodemon": "^2.0.7",
    "typescript": "^4.2.4"
  },
  "dependencies": {
    "@flamesx_128/discord.js_cmds": "^3.0.0",
    "discord.js": "^12.5.3"
  }
}

TS/index.ts

import { config } from 'dotenv';
config();

import { readCommands, readFiles } from '@flamesx_128/discord.js_cmds';
import { Client, Message } from 'discord.js';
const client = new Client();
const prefix = "!";

client.on('ready', async () => {
    await readFiles(__dirname, 'commands');
    console.log('Bot ready!');
});

client.on('message', async (message: Message) => {
    if (message.author.bot) return;
    await readCommands(prefix, message);
});

client.login(process.env.BOT);

TS/commands/cmdPing.ts

import { commandBase } from '@flamesx_128/discord.js_cmds';

module.exports = new class cmdPing extends commandBase {
    constructor() {
        super();
        this.Command = {
            name: 'ping',
            aliases: null,
            category: ['fun'],
            activated: true
        };
    };

    async execute(prefix: string, message: any, args: string[]) {
        message.reply(`Pong! \nAPI latency: ${message.client.ws.ping}ms.`);
    };
};

Example JS(JavaScript):

package.json

{
  "dependencies": {
    "@flamesx_128/discord.js_cmds": "^3.0.0",
    "discord.js": "^12.5.3"
  }
}

index.js

const { readFiles, readCommands } = require('@flamesx_128/discord.js_cmds');
const { Client } = require("discord.js");
const client = new Client();
const prefix = "$";

client.on("ready", async () => {
    await readFiles(__dirname, "cmds");
});

client.on("message", async (message) => {
    if (message.author.bot) return;
    if (message.content.startsWith(!prefix)) return;

    await readCommands(prefix, message);
});

client.login("SECRET TOKEN");

cmds/ping.js

const { commandBase } = require('@flamesx_128/discord.js_cmds');

module.exports = new class Ping extends commandBase {
    constructor(Command){
        super(Command);
        this.Command = {
            name: "ping",
            aliases: null,
            category: null,
            activated: true
        };
    };

    execute = (prefix, message, args) => {
        message.channel.send("Pong!");
    };
};

More Examples:


I need...:

You can report a bug, request an improvement and/or give ideas here:
[Github/Discord.js_cmds/issues]


If you need help you can go to my discord:

Discord

About

This package helps you create discord.js commands more easily.

Resources

License

Stars

Watchers

Forks

Packages

No packages published