3.0.1 • Published 3 years ago

@gary50613/discord.js-command-handler v3.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

discord.js-command-handler

Simple command handler for discord.js

[繁體中文](docs/README-zh.md)


Install

run this in your terminal

npm i @gary50613/discord.js-command-handler

Test

npm i
npm test

✨ Features

  • easy to set up
  • works perfectly with discord.js
  • ratelimit support
  • error handling with event
  • event listening
  • commands group support
  • SLASH COMMAND SUPPORT (beta)

Usage

JavaScript

basic how to initialize with [options](#options)

const Discord = require('discord.js')

// import a command
const ping = require("./commands/ping")

const bot = new Discord.Client()
require("@gary50613/djs-command-handler")(bot, {
	prefix: '.',
	// options
})

// load a whole folder's commands
bot.commands.loadCommands("./commands")

// register a command
bot.commands.register(new ping())

// or register multiple command at the same time
bot.commands.register(new ping(), ..., ...)

// listen to event
bot.commands.on("dm", (m) => {
    m.channel.send("u can only use command in a guild!")
})

bot.login(process.env.TOKEN)

make a command

const { Command } = require("@gary50613/djs-command-handler")

class Ping extends Command {
    constructor() {
        super(
            "ping", // name
            "ping the bot", // description
            ".ping", // usage
            "general", // group
            ["pong"] // alias
        );
    }
    
    // execute function to call
    async execute(bot, message, args) {
        // just write like normal discord.js
        message.reply('pong!')
    }
}

module.exports = Ping

TypeScript

basic how to initialize with [options](#options)

import { Client } from "discord.js"
import init from "@gary50613/discord.js-command-handler"

// import a command
import ping from "./commands/Ping"

const bot = new Client()
init(bot, {
    prefix: ".",
    // options
})

// load a whole folder's commands
bot.commands.loadFolder("./commands")

// register a command
bot.commands.register(new ping())

// or register multiple command at the same time
bot.commands.register(new ping(), ..., ...)

// listen to event
bot.commands.on("dm", (m) => {
    m.channel.send("u can only use command in a guild!")
})

bot.login(process.env.TOKEN)

make a command

import { Command } from "@gary50613/discord.js-command-handler";
import { Client, Guild, GuildMember, Message } from "discord.js";

export default class Ping extends Command {
    public constructor() {
        super(
            "ping", // name
            "ping the bot", // description
            ".ping", // usage
            "general", // group
            ["pong"] // alias
        );
    }

    public async execute(bot: Client, message: Message, args: string[]) {
        // just write like normal discord.js
        message.reply("pong!")
    }
}

Event

typedescriptionparameter
dmuser execute a command in dmMessage
ratelimituser get ratelimitedMillisecond, Message
executecommand successfully executedCommand, Message
errorcommand execute errorError, Command, Message
promiseErrorpromise rejectionError, Command, Message

Reference

options

{
    ratelimit: {
        enable: false, // whether enable ratelimit
        interval: 5000, // interval to limit
        bypass: {
            users: [], // specific users ID can bypass ratelimit 
            permissions: ["ADMINISTRATOR"], // specific perimissions FLAG can bypass ratelimit
            roles: [] // // specific roles ID can bypass ratelimit
        }
    },
    prefix: "PREFIX", // bot's prefix
    dm: false, // whether accept dm commands
    bot: false // whether accept bot execute command  
}

Author

🧑‍💻 Kane

  • Github [@Gary50613](https://github.com/Gary50613)

❤️ Contributing

Feel free to open [issue](https://github.com/Gary50613/discordjs-command-handler/issues) or join [my discord server](https://discord.gg/ct2ufag)

3.0.1

3 years ago

3.0.0

3 years ago

2.6.0

3 years ago

2.5.3

3 years ago

2.5.2

3 years ago

2.5.0

3 years ago

2.5.1

3 years ago

2.4.4

3 years ago

2.4.1

3 years ago

2.4.3

3 years ago

2.4.2

3 years ago

2.3.2

3 years ago

2.4.0

3 years ago

2.3.1

3 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.1.0

3 years ago

2.0.3

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

2.0.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.1.0

3 years ago