npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gary50613/discord.js-command-handler

v3.0.1

Published

simple discord.js v13 command handler

Downloads

51

Readme

discord.js-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(
            "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

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

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