Giter Club home page Giter Club logo

discordjs-command-handler's Introduction

djs-command-handler

Simple command handler for discord.js

繁體中文


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

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({
          name: "ping",
          description: "ping the bot",
          usage: ".ping",
          group: "ganeral",
          alias: ["pong"]
        });
    }
    
    // execute function to call
    async execute(bot, message, args, member, guild) {
        // just write like normal discord.js
        message.reply('pong!')
    }
}

module.exports = Ping

TypeScript

basic how to initialize with 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({
          name: "ping",
          description: "ping the bot",
          usage: ".ping",
          group: "ganeral",
          alias: ["pong"]
        });
    }

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

Event

type description parameter
dm user execute a command in dm Message
ratelimit user get ratelimited Millisecond, Message
execute command successfully executed Command, Message
error command execute error Error, Command, Message
promiseError promise rejection Error, 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

❤️ Contributing

Feel free to open issue or join my discord server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.