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

dchandler.js

v2.0.1

Published

Discord bot handler

Downloads

255

Readme

DCHandler.js

NPM Badge

About

DCHandler.js is the simple, powerful and straight to the point command handler for discord.js v14.

Features

  • ES6
  • Powerful and simple.
  • Easy object based command structure.
  • Per-Guild prefix(s) support using mongoDB.
  • Debugging and logging.

Installation

Requires Node 12.0.0 or newer.

Installing with npm:

npm i dchandler.js

Example Usage

Basic setup

index.js

import { Client, GatewayIntentBits } from 'discord.js'
import HandlerClient from 'dchandler.js'

const client = new Client({
    intents: [], // Your bots required Intents.
})

const handler = new HandlerClient(client, { // Pass in discord.js client and options.
                                                    // All options are fully optional.  
    commandPath: "commands", // Commands folder.
    eventPath: "events", // Commands folder.
    MongoURI: "mongodb://localhost:27017/test", // URI to connect to a mongoDB database
    PREFIX: "$" // Default bot prefix.
})

client.login('token')// Your bots token.

Config

By default DCH will try and load config.json or.env.

If it is unable to locate config.json or .env default values will be loaded instead.

If a config.json or .env is loaded, values will be overwritten by any values passed in as an Object.

With that if a config.json and .env are loaded, .env will overwrite config.json values.

Default values:

  • PREFIX: '$'
  • CommandPath: 'commands'

Pass in an object.

const handler = new Handler.HandlerClient(client, { //options
    commandPath: "commands", // Commands folder.
    eventPath: "events", // Commands folder.
    MongoURI: "mongodb://localhost:27017/test", // URI to connect to a mongoDB database
    PREFIX: "$" // Default bot prefix.
})

Pass in path to json file.

const handler = new HandlerClient(client, 'config')

Auto load a .env or config.json

const handler = new HandlerClient(client)

A .json file can be structured as such.

This will load all of the .json file's contents into Options.

Same applies to .env.

{
    "commandPath": "commands",
    "eventPath": "events",
    "MongoURI": "mongodb://localhost:27017/test",
    "PREFIX": "$" 
}

or

This will only load the "Handler":{...} object into Options.

{
    "Handler": {
        "commandPath": "commands",
        "eventPath": "events",
        "MongoURI": "mongodb://localhost:27017/test",
        "PREFIX": "$"
    }
}

Per-Guild prefix(s)

If no MongoURI path is passed in, Dch will not use per Guild prefixing and will strictly use the default prefix.

If a MongoURI is passed in and a connection to mongoDB is successful, Dch will use the prefix assigned to that guild. If there isn't an assigned prefix in the data base. The default prefix is used instead.

Basic command

ping.js

export default {
/**
    Information about the command.
    Name
    aliases
    ect...

    Anything put here can be accessed for custom features such as a help command.
*/
    name: 'ping', // Name and aliases are used by the command handler to call the command.
    aliases: [],
    execute(client, message, args) {// Any code put inside the execute call back will be executed when the command is ran.
        message.react("🏓")
        return message.channel.send(`**${client.ws.ping}ms** 🛰️`)
    },
}

Commands can be Exported as:

  • export default {}
  • export const command = {}
  • export const Command = {}

Basic Event

guildCreate.js

// Unlike a Command the name of the file is what events get identified by.
export default (client, guild) => { // Options needed for this event, client is always required. Guild is the event callback.
    guild.systemChannel.send(`Hello!`).then(sentMessage => {
        sentMessage.react('👋')
        console.log(`Joined the guild: ${guild.name}!`)
    })
}

// This is replicating

/** 
client.on('guildCreate', guild => {
    guild.systemChannel.send(`Hello!`).then(sentMessage => {
        sentMessage.react('👋')
        console.log(`Joined the guild: ${guild.name}!`)
    })
}) 
*/

Events can be Exported as:

  • export default {}
  • export const event = {}
  • export const Event = {}

Change prefix command

changePrefix.js

import { db } from 'dchandler.js'

export default {
    name: 'changePrefix',
    aliases: ['cp'],
    execute(client, message, args) {
        if (!args[0]) return message.channel.send(`No given prefix!`)
        new db().setPrefix(args[0], message)
        return message.channel.send(`Changed prefix to ${args[0]} !`)
    },
}

Options

  • PREFIX [string]
  • commandPath [string]
  • eventPath [string]
  • MongoURI [string]

Start up Flags

  • --debug
  • --clear
  • --ignore-warnings
  • --v | --version
  • --p-v | --project-versions
node index.js --debug

Shows handler debug information such as loader status.

node index.js --ignore-warnings

Hides 'Loaded with _ warnings!' messages.

node index.js --clear

Hides all handler console messages.

node index.js --v --p-v
  • --v Shows Handler version.
  • --p-v Shows All relevant project versions.

AudioBoi

My music bot that is built with DCHandler.js.

Example bot with this package

My repo: Example-Discord-Bot

Me

  • Discord: macen#0001
  • Github: https://github.com/macen648
  • Npm: https://www.npmjs.com/~macen

License

MIT

Free Software, Hell Yeah!

Made with love

Macen <3